summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test
diff options
context:
space:
mode:
authorGary Wu <gary.i.wu@huawei.com>2017-05-08 23:04:31 -0700
committerGary Wu <gary.i.wu@huawei.com>2017-05-16 12:13:01 -0700
commitccf361a446c19d1c67ed1adf4db191be67c3cf58 (patch)
treeba3cb105d5b37881b15b8c9db5f9289341c41675 /appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test
parent753cb638fcb58f355f2c979e9e0a43cba2832984 (diff)
Refactor CommandTask classes to be immutable
Refactor CommandTask and its subclasses to be immutable. Also made CommandResponse immutable. Change-Id: I9ea1b57fdff677b163c0fe9ad5d48f24b781a08f Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
Diffstat (limited to 'appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test')
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java29
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java4
2 files changed, 14 insertions, 19 deletions
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java
index 7bf9f7c03..f2c30990e 100644
--- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java
@@ -72,8 +72,6 @@ public class TestCommandExecutionTask {
private static final String TTL_FLAG= "TTL";
private static final String API_VERSION= "2.0.0";
private static final String ORIGINATOR_ID= "1";
- private LCMCommandTask executionTask;
- private LCMReadonlyCommandTask LCMReadonlyCommandTask;
private CommandTaskFactory factory ;
private RequestHandler requestHandler;
@@ -119,8 +117,6 @@ public class TestCommandExecutionTask {
workflowManager = Mockito.mock(WorkFlowManager.class);
lifecyclemanager = Mockito.mock(LifecycleManager.class );
- executionTask = new LCMCommandTask(requestHandler,workflowManager,lifecyclemanager);
- LCMReadonlyCommandTask = new LCMReadonlyCommandTask(requestHandler,workflowManager);
factory = new CommandTaskFactory();
factory.setLifecyclemanager(lifecyclemanager);
factory.setWorkflowManager(workflowManager);
@@ -131,9 +127,9 @@ public class TestCommandExecutionTask {
@Test
public void testFactory(){
- CommandTask task = factory.getExecutionTask("Configure");
+ CommandTask task = factory.getExecutionTask("Configure", null);
assertEquals(LCMCommandTask.class,task.getClass() );
- task = factory.getExecutionTask("Sync");
+ task = factory.getExecutionTask("Sync", null);
assertEquals(LCMReadonlyCommandTask.class,task.getClass() );
}
@@ -145,35 +141,34 @@ public class TestCommandExecutionTask {
Mockito.doNothing().when(requestHandler).onRequestTTLEnd((RuntimeContext) anyObject(),anyBoolean());
RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", "");
CommandResponse response = getCommandResponse(VNFOperation.Configure, true, "11", "","1");
- executionTask.onRequestCompletion(request, response);
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
+ executionTask.onRequestCompletion(response);
}
@Test
public void testRunGetConfig(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- LCMReadonlyCommandTask.setCommandRequest(request);
- LCMReadonlyCommandTask.run();
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ LCMReadonlyCommandTask readonlyCommandTask = new LCMReadonlyCommandTask(request, requestHandler,workflowManager);
+ readonlyCommandTask.run();
}
@Test
public void testRun(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- executionTask.setCommandRequest(request);
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
executionTask.run();
}
@Test
public void testRunNegative(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
- executionTask.setCommandRequest(request);
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager);
executionTask.run();
}
CommandResponse getCommandResponse(VNFOperation action , boolean success, String responseId, String payload, String vnfId){
- CommandResponse commandResponse = new CommandResponse();
RuntimeContext runtimeContext = new RuntimeContext();
- commandResponse.setRuntimeContext(runtimeContext);
ResponseContext responseContext = new ResponseContext();
runtimeContext.setResponseContext(responseContext);
RequestContext requestContext = new RequestContext();
@@ -194,7 +189,7 @@ public class TestCommandExecutionTask {
responseContext.setPayload(payload);
commonHeader.setTimestamp(Instant.now());
vnfContext.setId(vnfId);
- return commandResponse;
+ return new CommandResponse(runtimeContext);
}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java
index 7e972b738..cd33e8b2e 100644
--- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java
@@ -80,8 +80,8 @@ public class TestCommandExecutor {
commandExecutor.setExecutionQueueService(executionQueueService);
LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class);
LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class);
- Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure");
- Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync");
+ Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null);
+ Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null);
// Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true);
}