diff options
Diffstat (limited to 'src/test/java/org/onap')
3 files changed, 284 insertions, 1 deletions
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 |