diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2017-09-18 11:10:02 +0200 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2017-09-18 11:10:02 +0200 |
commit | af0fbf9edb92544380d40ab2cffb87c89831944f (patch) | |
tree | 95847af9e392b28ab92232e27c74882675a0e0a3 | |
parent | 52a9b022e0b7211e48162b75610ceb7df8c91f5a (diff) |
Add new tests to CLAMP
New tests added on ModelProperties, CldsModel and ITs (CldsService
tests)
Change-Id: I75a29c11ec66e0eef7c80f76cf90c30b2fc29972
Issue-ID: CLAMP-54
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
7 files changed, 488 insertions, 9 deletions
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsModel.java b/src/main/java/org/onap/clamp/clds/model/CldsModel.java index 7eac3d92a..62b10d44f 100644 --- a/src/main/java/org/onap/clamp/clds/model/CldsModel.java +++ b/src/main/java/org/onap/clamp/clds/model/CldsModel.java @@ -116,7 +116,7 @@ public class CldsModel { public boolean canInventoryCall() { boolean canCall = false; - /* Below checks the clds ecent is submit/resubmit */ + /* Below checks the clds event is submit/resubmit */ if ((event.isActionCd(CldsEvent.ACTION_SUBMIT) || event.isActionCd(CldsEvent.ACTION_RESUBMIT))) { canCall = true; @@ -225,7 +225,9 @@ public class CldsModel { /** * Determine permittedActionCd list using the actionCd from the current - * event. + * event. It's a states graph, given the next action that can be executed + * from the one that has been executed (described in the event object). + * ACTION_CREATE being the first one. */ private void determinePermittedActionCd() { String actionCd = getCurrentActionCd(); diff --git a/src/main/java/org/onap/clamp/clds/service/DefaultUserNameHandler.java b/src/main/java/org/onap/clamp/clds/service/DefaultUserNameHandler.java index 511cafe1e..574689e5b 100644 --- a/src/main/java/org/onap/clamp/clds/service/DefaultUserNameHandler.java +++ b/src/main/java/org/onap/clamp/clds/service/DefaultUserNameHandler.java @@ -29,9 +29,6 @@ import javax.ws.rs.core.SecurityContext; public class DefaultUserNameHandler implements UserNameHandler {
- public DefaultUserNameHandler() {
- }
-
/*
* (non-Javadoc)
*
diff --git a/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java b/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java index 19813ebaf..acbd8bbd4 100644 --- a/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java +++ b/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java @@ -23,6 +23,9 @@ package org.onap.clamp.clds.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + import java.security.Principal; import javax.ws.rs.NotAuthorizedException; @@ -31,9 +34,6 @@ import javax.ws.rs.core.SecurityContext; import org.onap.clamp.clds.util.LoggingUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - /** * Base/abstract Service class. Implements shared security methods. */ @@ -185,4 +185,9 @@ public abstract class SecureServiceBase { userNameHandler = handler; } } + + public void setSecurityContext(SecurityContext securityContext) { + this.securityContext = securityContext; + } + } diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceIT.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceIT.java new file mode 100644 index 000000000..96131197b --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceIT.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.security.Principal; +import java.util.Properties; + +import javax.ws.rs.core.SecurityContext; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.clamp.clds.AbstractIT; +import org.onap.clamp.clds.model.CldsInfo; +import org.onap.clamp.clds.service.CldsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@TestPropertySource(locations = "classpath:application-no-camunda.properties") +public class CldsServiceIT extends AbstractIT { + + @Autowired + CldsService cldsService; + + @Test + public void testCldsInfoNotAuthorized() throws Exception { + SecurityContext securityContext = Mockito.mock(SecurityContext.class); + Principal p = Mockito.mock(Principal.class); + Mockito.when(p.getName()).thenReturn("admin"); + + Mockito.when(securityContext.getUserPrincipal()).thenReturn(p); + cldsService.setSecurityContext(securityContext); + + CldsInfo cldsInfo = cldsService.getCldsInfo(); + assertFalse(cldsInfo.isPermissionReadCl()); + assertFalse(cldsInfo.isPermissionReadTemplate()); + assertFalse(cldsInfo.isPermissionUpdateCl()); + assertFalse(cldsInfo.isPermissionUpdateTemplate()); + } + + @Test + public void testCldsInfoAuthorized() throws Exception { + + SecurityContext securityContext = Mockito.mock(SecurityContext.class); + Principal p = Mockito.mock(Principal.class); + Mockito.when(p.getName()).thenReturn("admin"); + + Mockito.when(securityContext.getUserPrincipal()).thenReturn(p); + Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true); + Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true); + Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true); + Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true); + + cldsService.setSecurityContext(securityContext); + + CldsInfo cldsInfo = cldsService.getCldsInfo(); + assertTrue(cldsInfo.isPermissionReadCl()); + assertTrue(cldsInfo.isPermissionReadTemplate()); + assertTrue(cldsInfo.isPermissionUpdateCl()); + assertTrue(cldsInfo.isPermissionUpdateTemplate()); + + Properties prop = new Properties(); + // InputStream in = + // CldsInfo.class.getResourceAsStream("clds-version.properties"); + InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("clds-version.properties"); + prop.load(in); + in.close(); + + assertEquals(cldsInfo.getCldsVersion(), prop.getProperty("clds.version")); + assertEquals(cldsInfo.getUserName(), "admin"); + } +} diff --git a/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java b/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java index 461b3ae41..0333bdb78 100644 --- a/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java +++ b/src/test/java/org/onap/clamp/clds/model/CldsModelTest.java @@ -24,6 +24,7 @@ package org.onap.clamp.clds.model; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import javax.ws.rs.BadRequestException; @@ -45,10 +46,177 @@ public class CldsModelTest { utilCreateUsingControlName("", "c42aceb-2350-11e6-8131-fa163ea8d2da"); } + @Test(expected = IllegalArgumentException.class) + public void testValidateActionEmptyEvent() { + CldsModel cldsModel = new CldsModel(); + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + } + + @Test(expected = IllegalArgumentException.class) + public void testValidateActionNotExist() { + CldsModel cldsModel = new CldsModel(); + cldsModel.validateAction("unknown"); + } + + @Test + public void testValidateActionFromCreate() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_CREATE); + cldsModel.validateAction(CldsEvent.ACTION_SUBMIT); + cldsModel.validateAction(CldsEvent.ACTION_TEST); + + try { + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + + @Test + public void testValidateActionFromSubmitOrReSubmit() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_SUBMIT); + cldsModel.validateAction(CldsEvent.ACTION_RESUBMIT); + try { + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_RESUBMIT); + cldsModel.validateAction(CldsEvent.ACTION_RESUBMIT); + try { + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + + @Test + public void testValidateActionFromDistribute() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_DISTRIBUTE); + cldsModel.validateAction(CldsEvent.ACTION_RESUBMIT); + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + + @Test + public void testValidateActionFromUndeploy() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_UNDEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_UPDATE); + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_RESUBMIT); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + + @Test + public void testValidateActionFromDeploy() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_UNDEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_UPDATE); + cldsModel.validateAction(CldsEvent.ACTION_STOP); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + + @Test + public void testValidateActionFromRestartOrUpdate() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_RESTART); + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_UPDATE); + cldsModel.validateAction(CldsEvent.ACTION_STOP); + cldsModel.validateAction(CldsEvent.ACTION_UNDEPLOY); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_UPDATE); + cldsModel.validateAction(CldsEvent.ACTION_DEPLOY); + cldsModel.validateAction(CldsEvent.ACTION_UPDATE); + cldsModel.validateAction(CldsEvent.ACTION_STOP); + cldsModel.validateAction(CldsEvent.ACTION_UNDEPLOY); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + + } + + @Test + public void testValidateActionFromDelete() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_DELETE); + cldsModel.validateAction(CldsEvent.ACTION_SUBMIT); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_DELETE); + cldsModel.getEvent().setActionStateCd(CldsEvent.ACTION_STATE_SENT); + + try { + cldsModel.validateAction(CldsEvent.ACTION_SUBMIT); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + + @Test + public void testValidateActionFromStop() { + CldsModel cldsModel = new CldsModel(); + cldsModel.getEvent().setActionCd(CldsEvent.ACTION_STOP); + cldsModel.validateAction(CldsEvent.ACTION_UPDATE); + cldsModel.validateAction(CldsEvent.ACTION_RESTART); + cldsModel.validateAction(CldsEvent.ACTION_UNDEPLOY); + + try { + cldsModel.validateAction(CldsEvent.ACTION_CREATE); + fail("Exception should have been sent"); + } catch (IllegalArgumentException e) { + + } + } + /** * Utility Method to create model from controlname and uuid. */ - public void utilCreateUsingControlName(String controlNamePrefix, String controlNameUuid) { CldsModel model = CldsModel.createUsingControlName(controlNamePrefix + controlNameUuid); assertEquals(controlNamePrefix, model.getControlNamePrefix()); diff --git a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java index 02e27ea8f..efeae00d2 100644 --- a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java +++ b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java @@ -32,6 +32,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; +import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.util.ResourceFileUtil; /** @@ -85,4 +86,12 @@ public class ModelPropertiesTest { assertEquals("policy1", holmes.getOperationalPolicy()); assertEquals("blabla", holmes.getCorrelationLogic()); } + + @Test + public void testGetVf() throws IOException { + CldsModel cldsModel = new CldsModel(); + cldsModel.setPropText( + ResourceFileUtil.getResourceAsString("example/model-properties/modelBpmnPropWithGlobal.json")); + assertEquals("f5213e3a-9191-4362-93b5-b67f8d770e44", ModelProperties.getVf(cldsModel)); + } }
\ No newline at end of file diff --git a/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json b/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json new file mode 100644 index 000000000..5abb28a8c --- /dev/null +++ b/src/test/resources/example/model-properties/modelBpmnPropWithGlobal.json @@ -0,0 +1,192 @@ +{ + "collector": { + "topicPublishes": { + "DCAE-COLLECTOR-UCSNMP": "DCAE-COLLECTOR-UCSNMP", + "GFP-IP-AIC-SNMP-TRAPS": "GFP-IP-AIC-SNMP-TRAPS", + "AIC-SNMP-TRAPS": "AIC-SNMP-TRAPS" + } + }, + "string_match": { + "topicPublishes": { + "DCAE-CL-EVENT": "DCAE-CL-EVENT" + }, + "aaiMatchingFields": { + "cloud-region.identity-url": "cloud-region.identity-url", + "complex.city": "complex.city", + "complex.physical-location-id": "complex.physical-location-id", + "complex.state": "complex.state", + "generic-vnf.service-id": "generic-vnf.service-id", + "generic-vnf.vnf-name": "generic-vnf.vnf-name", + "generic-vnf.vnf-type": "generic-vnf.vnf-type", + "tenant.tenant-id": "tenant.tenant-id", + "vserver.in-maint": "vserver.in-maint", + "vserver.is-closed-loop-disabled": "vserver.is-closed-loop-disabled", + "vserver.l-interface.interface-name": "vserver.l-interface.interface-name", + "vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address": "vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address", + "vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address": "vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", + "vserver.l-interface.network-name": "vserver.l-interface.network-name", + "vserver.prov-status": "vserver.prov-status", + "vserver.selflink": "vserver.selflink", + "vserver.vserver-id": "vserver.vserver-id", + "vserver.vserver-name": "vserver.vserver-name" + }, + "aaiSendFields": { + "cloud-region.identity-url": "cloud-region.identity-url", + "complex.city": "complex.city", + "complex.physical-location-id": "complex.physical-location-id", + "complex.state": "complex.state", + "generic-vnf.service-id": "generic-vnf.service-id", + "generic-vnf.vnf-name": "generic-vnf.vnf-name", + "generic-vnf.vnf-type": "generic-vnf.vnf-type", + "tenant.tenant-id": "tenant.tenant-id", + "vserver.in-maint": "vserver.in-maint", + "vserver.is-closed-loop-disabled": "vserver.is-closed-loop-disabled", + "vserver.l-interface.interface-name": "vserver.l-interface.interface-name", + "vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address": "vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address", + "vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address": "vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", + "vserver.l-interface.network-name": "vserver.l-interface.network-name", + "vserver.prov-status": "vserver.prov-status", + "vserver.selflink": "vserver.selflink", + "vserver.vserver-id": "vserver.vserver-id", + "vserver.vserver-name": "vserver.vserver-name" + }, + "eventSourceType": { + "f5BigIP": "f5BigIP", + "vSBG_Alarms": "vSBG_Alarms", + "vCTS_Alarms": "vCTS_Alarms" + }, + "eventSeverity": { + "NORMAL": "NORMAL", + "not-NORMAL": "not-NORMAL", + "OK": "OK", + "WARNING": "WARNING", + "MINOR": "MINOR", + "MAJOR": "MAJOR", + "CRITICAL": "CRITICAL" + }, + "timeWindow": 0, + "ageLimit": 1600, + "outputEventName": { + "": "", + "ONSET": "ONSET", + "ABATED": "ABATED" + }, + "createClosedLoopEventId": { + "Initial": "Initial", + "Close": "Close" + } + }, + "tca": { + "tname": "New_Set", + "tcaInt": "1", + "tcaVio": "1", + "tcaSev": { + "NORMAL": "NORMAL", + "CRITICAL": "CRITICAL", + "MAJOR": "MAJOR", + "MINOR": "MINOR", + "WARNING": "WARNING" + }, + "fieldPath": { + "FIELDPATH_test_1": "FIELDPATH_test_1", + "FIELDPATH_test_2": "FIELDPATH_test_2" + }, + "operator": { + ">": "GREATER", + "=": "EQUAL", + "<": "LESS" + }, + "opsPolicy": { + "POLICY_test_X": "POLICY_test_X", + "POLICY_test_Y": "POLICY_test_Y" + } + }, + "global": [ + { + "name": "actionSet", + "value": [ + "vnfRecipe" + ] + }, + { + "name": "location", + "value": [ + "SNDGCA64", + "ALPRGAED" + ] + }, + { + "name": "vf", + "value": [ + "f5213e3a-9191-4362-93b5-b67f8d770e44" + ] + }, + { + "name": "location", + "value": [ + "SNDGCA64", + "ALPRGAED", + "LSLEILAA", + "MDTWNJC1" + ] + } + ], + "policy": { + "pname": "0", + "timeout": 345, + "vnfRecipe": { + "": "", + "restart": "Restart", + "rebuild": "Rebuild", + "migrate": "Migrate", + "healthCheck": "Health Check", + "evacuate": "Evacuate" + }, + "enbRecipe": { + "": "", + "reset": "Reset" + }, + "maxRetries": "3", + "retryTimeLimit": 180, + "resource": { + "vCTS": "vCTS", + "v3CDB": "v3CDB", + "vUDR": "vUDR", + "vCOM": "vCOM", + "vRAR": "vRAR", + "vLCS": "vLCS", + "vUDR-BE": "vUDR-BE", + "vDBE": "vDBE" + }, + "parentPolicyConditions": { + "Failure_Retries": "Failure: Max Retries Exceeded", + "Failure_Timeout": "Failure: Time Limit Exceeded", + "Failure_Guard": "Failure: Guard", + "Failure_Exception": "Failure: Exception", + "Failure": "Failure: Other", + "Success": "Success" + } + }, + "shared": { + "byService": { + "": { + "vf": { + "": "" + }, + "location": { + "": "" + }, + "alarmCondition": { + "": "" + } + } + }, + "byVf": { + "": { + "vfc": { + "": "" + } + } + } + } +}
\ No newline at end of file |