Ray Milkey
Committed by Gerrit Code Review

Fix delete of an intent and add a unit test for it

Change-Id: If28dc96b299ab205e5519aac74d98e2588d1c37b
......@@ -149,7 +149,7 @@ public class IntentsWebResource extends AbstractWebResource {
if (intent == null) {
intent = service
.getIntent(Key.of(Long.parseLong(keyString), app));
.getIntent(Key.of(Long.decode(keyString), app));
}
if (intent == null) {
// No such intent. REST standards recommend a positive status code
......
......@@ -38,6 +38,7 @@ import org.onosproject.core.CoreService;
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.IdGenerator;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.FakeIntentManager;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
......@@ -387,4 +388,45 @@ public class IntentsResourceTest extends ResourceTest {
String location = response.getLocation().getPath();
assertThat(location, Matchers.startsWith("/intents/2/"));
}
/**
* Tests removing an intent with DELETE.
*/
@Test
public void testRemove() {
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final Intent intent = new MockIntent(3L, resources);
final ApplicationId appId = new DefaultApplicationId(2, "app");
IntentService fakeManager = new FakeIntentManager();
expect(mockCoreService.getAppId("app"))
.andReturn(appId).once();
replay(mockCoreService);
mockIntentService.withdraw(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
expect(mockIntentService.getIntent(Key.of(2, appId)))
.andReturn(intent)
.once();
expect(mockIntentService.getIntent(Key.of("0x2", appId)))
.andReturn(null)
.once();
mockIntentService.addListener(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
mockIntentService.removeListener(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
replay(mockIntentService);
WebResource rs = resource();
ClientResponse response = rs.path("intents/app/0x2")
.type(MediaType.APPLICATION_JSON_TYPE)
.delete(ClientResponse.class);
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
}
......