var errorMessage: String?,
var buildingBlockName: String?,
var buildingBlockStep: String?,
+ var description: String?,
+ var timeout: String?,
var validResponses: List<String>?
) {
// i.e. "default constructor", no params
constructor() : this(
null, null, null, null,
null, null, null, null,
- null, null, null, null
+ null, null, null,
+ null, null, null
)
}
};
function loadAvailableTasks(requestId) {
- MsoService.getManualTasks(requestId)
+ return MsoService.getManualTasks(requestId)
.then(function(response) {
vm.task = response.data[0];
vm.manualTasks = vm.task && vm.task.validResponses;
+ vm.description = vm.task && vm.task.description || null;
+ vm.timeout = vm.task && vm.task.timeout || null;
})
.catch(function(error) {
$log.error(error);
return vm.manualTasks.includes(task);
};
+ vm.__test_only__ = {
+ loadAvailableTasks: loadAvailableTasks,
+ };
+
init();
}
})();
);
beforeEach(inject(function (_$controller_) {
- $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
- {data: [manualTaskResponse]});
$log.error = jestMock.fn();
+ $uibModalInstance.close = jestMock.fn();
+
+ mockManualTaskResponse(manualTaskResponse);
$controller = _$controller_('changeManagementManualTasksController', {
"MsoService": $MsoService,
});
}));
+ function mockManualTaskResponse(manualTaskResponse) {
+ $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
+ {data: [manualTaskResponse]}
+ );
+ }
+
const job = {
"requestId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
"requestScope": "vnf",
}
};
- const manualTaskResponse = {
+ const manualTaskResponseWithoutValidResponses = {
"taskId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
- "validResponses": ["rollback", "abort", "skip", "resume", "retry"]
};
+ const manualTaskResponse = Object.assign({
+ "validResponses": ["rollback", "abort", "skip", "resume", "retry"],
+ }, manualTaskResponseWithoutValidResponses);
+
+ const manualTaskResponseWithTimeout = Object.assign({
+ description: 'description',
+ timeout: 'timeout',
+ }, manualTaskResponse);
+
test('should populate vm.manualTasks (while init)', () => {
expect($controller.manualTasks).toEqual(
manualTaskResponse.validResponses);
});
+ test('should undefine vm.manualTasks when ValidResponses not given', () => {
+ // given
+ mockManualTaskResponse(manualTaskResponseWithoutValidResponses);
+ // when
+ return $controller.__test_only__.loadAvailableTasks('anything')
+ .then(() => {
+ expect($controller.manualTasks).toBeUndefined()
+ });
+ });
+
test('should populate vm.MANUAL_TASKS from COMPONENT (while init)', () => {
expect($controller.MANUAL_TASKS).toEqual(
["manualTaskName1", "manualTaskName2"]);
expect($controller.task).toEqual(manualTaskResponse);
});
+ test('should nullify vm.description (while init)', () => {
+ expect($controller.description).toBeNull();
+ });
+
+ test('should nullify vm.timeout (while init)', () => {
+ expect($controller.timeout).toBeNull();
+ });
+
+ test('should populate vm.description', () => {
+ // given
+ mockManualTaskResponse(manualTaskResponseWithTimeout);
+ // when
+ return $controller.__test_only__.loadAvailableTasks('anything')
+ .then(() => {
+ expect($controller.description).toEqual('description');
+ });
+ });
+
+ test('should populate vm.timeout', () => {
+ // given
+ mockManualTaskResponse(manualTaskResponseWithTimeout);
+ // when
+ return $controller.__test_only__.loadAvailableTasks('anything')
+ .then(() => {
+ expect($controller.timeout).toEqual('timeout');
+ });
+ });
+
test('should find manual task using isTaskAvailable', () => {
expect($controller.isTaskAvailable('abort')).toBeTruthy();
expect($controller.isTaskAvailable('resume')).toBeTruthy();
public class TaskTest {
private final ObjectMapper mapper = new ObjectMapper();
- private final String TASK_JSON = ""
- + "{ "
- + " \"taskId\": \"taskId\", "
- + " \"type\": \"type\", "
- + " \"nfRole\": \"nfRole\", "
- + " \"subscriptionServiceType\": \"subscriptionServiceType\", "
- + " \"originalRequestId\": \"originalRequestId\", "
- + " \"originalRequestorId\": \"originalRequestorId\", "
- + " \"buildingBlockName\": \"buildingBlockName\", "
- + " \"buildingBlockStep\": \"buildingBlockStep\", "
- + " \"errorSource\": \"errorSource\", "
- + " \"errorCode\": \"errorCode\", "
- + " \"errorMessage\": \"errorMessage\", "
- + " \"validResponses\": [ "
- + " \"a\", "
- + " \"b\", "
- + " \"c\" "
- + " ] "
- + "} ";
+
+ private String templateTaskJson(String insertion) {
+ return ""
+ + "{ "
+ + " \"taskId\": \"taskId\", "
+ + " \"type\": \"type\", "
+ + " \"nfRole\": \"nfRole\", "
+ + " \"subscriptionServiceType\": \"subscriptionServiceType\", "
+ + " \"originalRequestId\": \"originalRequestId\", "
+ + " \"originalRequestorId\": \"originalRequestorId\", "
+ + " \"buildingBlockName\": \"buildingBlockName\", "
+ + " \"buildingBlockStep\": \"buildingBlockStep\", "
+ + " \"errorSource\": \"errorSource\", "
+ + " \"errorCode\": \"errorCode\", "
+ + " \"errorMessage\": \"errorMessage\", "
+ + insertion
+ + " \"validResponses\": [ "
+ + " \"a\", "
+ + " \"b\", "
+ + " \"c\" "
+ + " ] "
+ + "} ";
+ }
+
+ private final String TASK_JSON = templateTaskJson(""
+ + " \"description\": \"description\", "
+ + " \"timeout\": \"timeout\", "
+ );
+
+ private final String TASK_JSON_WITHOUT_TIMEOUT = templateTaskJson("");
private Task newTaskWithPopulatedFields() {
Task task = TestUtils.setStringsInStringProperties(new Task());
is(newTaskWithPopulatedFields())
);
}
+
+ @Test
+ public void deserializeTaskWithoutTimeout() throws IOException {
+ /*
+ SO may return no timeout, and therefore no description as well
+ */
+ final Task taskWithoutTimeout = newTaskWithPopulatedFields();
+ taskWithoutTimeout.setDescription(null);
+ taskWithoutTimeout.setTimeout(null);
+
+ assertThat(
+ mapper.readValue(TASK_JSON_WITHOUT_TIMEOUT, Task.class),
+ is(taskWithoutTimeout)
+ );
+ }
}