Committed by
Gerrit Code Review
Fix delete of an intent and add a unit test for it
Change-Id: If28dc96b299ab205e5519aac74d98e2588d1c37b
Showing
2 changed files
with
43 additions
and
1 deletions
... | @@ -149,7 +149,7 @@ public class IntentsWebResource extends AbstractWebResource { | ... | @@ -149,7 +149,7 @@ public class IntentsWebResource extends AbstractWebResource { |
149 | 149 | ||
150 | if (intent == null) { | 150 | if (intent == null) { |
151 | intent = service | 151 | intent = service |
152 | - .getIntent(Key.of(Long.parseLong(keyString), app)); | 152 | + .getIntent(Key.of(Long.decode(keyString), app)); |
153 | } | 153 | } |
154 | if (intent == null) { | 154 | if (intent == null) { |
155 | // No such intent. REST standards recommend a positive status code | 155 | // No such intent. REST standards recommend a positive status code | ... | ... |
... | @@ -38,6 +38,7 @@ import org.onosproject.core.CoreService; | ... | @@ -38,6 +38,7 @@ import org.onosproject.core.CoreService; |
38 | import org.onosproject.core.DefaultApplicationId; | 38 | import org.onosproject.core.DefaultApplicationId; |
39 | import org.onosproject.core.IdGenerator; | 39 | import org.onosproject.core.IdGenerator; |
40 | import org.onosproject.net.NetworkResource; | 40 | import org.onosproject.net.NetworkResource; |
41 | +import org.onosproject.net.intent.FakeIntentManager; | ||
41 | import org.onosproject.net.intent.Intent; | 42 | import org.onosproject.net.intent.Intent; |
42 | import org.onosproject.net.intent.IntentService; | 43 | import org.onosproject.net.intent.IntentService; |
43 | import org.onosproject.net.intent.IntentState; | 44 | import org.onosproject.net.intent.IntentState; |
... | @@ -387,4 +388,45 @@ public class IntentsResourceTest extends ResourceTest { | ... | @@ -387,4 +388,45 @@ public class IntentsResourceTest extends ResourceTest { |
387 | String location = response.getLocation().getPath(); | 388 | String location = response.getLocation().getPath(); |
388 | assertThat(location, Matchers.startsWith("/intents/2/")); | 389 | assertThat(location, Matchers.startsWith("/intents/2/")); |
389 | } | 390 | } |
391 | + | ||
392 | + /** | ||
393 | + * Tests removing an intent with DELETE. | ||
394 | + */ | ||
395 | + @Test | ||
396 | + public void testRemove() { | ||
397 | + final HashSet<NetworkResource> resources = new HashSet<>(); | ||
398 | + resources.add(new MockResource(1)); | ||
399 | + resources.add(new MockResource(2)); | ||
400 | + resources.add(new MockResource(3)); | ||
401 | + final Intent intent = new MockIntent(3L, resources); | ||
402 | + final ApplicationId appId = new DefaultApplicationId(2, "app"); | ||
403 | + IntentService fakeManager = new FakeIntentManager(); | ||
404 | + | ||
405 | + expect(mockCoreService.getAppId("app")) | ||
406 | + .andReturn(appId).once(); | ||
407 | + replay(mockCoreService); | ||
408 | + | ||
409 | + mockIntentService.withdraw(anyObject()); | ||
410 | + expectLastCall().andDelegateTo(fakeManager).once(); | ||
411 | + expect(mockIntentService.getIntent(Key.of(2, appId))) | ||
412 | + .andReturn(intent) | ||
413 | + .once(); | ||
414 | + expect(mockIntentService.getIntent(Key.of("0x2", appId))) | ||
415 | + .andReturn(null) | ||
416 | + .once(); | ||
417 | + | ||
418 | + mockIntentService.addListener(anyObject()); | ||
419 | + expectLastCall().andDelegateTo(fakeManager).once(); | ||
420 | + mockIntentService.removeListener(anyObject()); | ||
421 | + expectLastCall().andDelegateTo(fakeManager).once(); | ||
422 | + | ||
423 | + replay(mockIntentService); | ||
424 | + | ||
425 | + WebResource rs = resource(); | ||
426 | + | ||
427 | + ClientResponse response = rs.path("intents/app/0x2") | ||
428 | + .type(MediaType.APPLICATION_JSON_TYPE) | ||
429 | + .delete(ClientResponse.class); | ||
430 | + assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT)); | ||
431 | + } | ||
390 | } | 432 | } | ... | ... |
-
Please register or login to post a comment