diff options
5 files changed, 489 insertions, 46 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogicTest.java index db95ee8827..d753b245af 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogicTest.java @@ -1,83 +1,249 @@ package org.openecomp.sdc.be.components.impl; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Before; import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.elements.ConsumerDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.ConsumerDefinition; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.ConsumerOperation; +import org.openecomp.sdc.be.resources.data.ConsumerData; +import org.openecomp.sdc.be.user.IUserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; - import fj.data.Either; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; public class ConsumerBusinessLogicTest { - private ConsumerBusinessLogic createTestSubject() { - return new ConsumerBusinessLogic(); + private User user; + private ConsumerDefinition consumer; + private ConsumerDataDefinition consumerDataDefinition; + + @InjectMocks + private ConsumerBusinessLogic consumerBusinessLogic; + + @Mock + private ComponentsUtils componentsUtils; + + @Mock + private IUserBusinessLogic iUserBusinessLogic; + + @Mock + private IGraphLockOperation iGraphLockOperation; + + @Mock + private ConsumerOperation consumerOperation; + + @Mock + private ConsumerData consumerData; + + @Before + public void setUp(){ + consumerBusinessLogic = new ConsumerBusinessLogic(); + consumerDataDefinition = new ConsumerDataDefinition(); + consumer = new ConsumerDefinition(); + MockitoAnnotations.initMocks(this); + user = new User("Stan", "Lee", "stan.lee", + "stan.lee@marvel.com", "ADMIN", 1542024000L); } - @Test - public void testCreateConsumer() throws Exception { - ConsumerBusinessLogic testSubject; - User user = null; - ConsumerDefinition consumer = null; - Either<ConsumerDefinition, ResponseFormat> result; + public void testCreateConsumer_givenMissingUser_thenReturnsError() { + User user = new User(); + ConsumerDefinition consumerDefinition = new ConsumerDefinition(); + Mockito.when(componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION)) + .thenReturn(new ResponseFormat()); + assertTrue(consumerBusinessLogic.createConsumer(user, consumerDefinition).isRight()); + } - // default test - testSubject = createTestSubject(); + @Test + public void testCreateConsumer_givenNonListedUser_thenReturnsError() { + ConsumerDefinition consumerDefinition = new ConsumerDefinition(); + Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS)) + .thenReturn(new ResponseFormat()); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.right(ActionStatus.RESTRICTED_OPERATION)); + assertTrue(consumerBusinessLogic.createConsumer(user, consumerDefinition).isRight()); } - + @Test + public void testCreateConsumer_givenNonAdminUser_thenReturnsError() { + user.setRole("DESIGNER"); + Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)) + .thenReturn(new ResponseFormat()); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isRight()); + } + + @Test + public void testCreateConsumer_givenInvalidConsumerNames_thenReturnsError() { + Map<String, ActionStatus> invalidConsumerNames = new HashMap<>(); + invalidConsumerNames.put(null, ActionStatus.MISSING_DATA); + invalidConsumerNames.put(".#()", ActionStatus.INVALID_CONTENT); + invalidConsumerNames.put(RandomStringUtils.random(256, true, false), ActionStatus.EXCEEDS_LIMIT); + for(Map.Entry<String, ActionStatus> e: invalidConsumerNames.entrySet()){ + consumer.setConsumerName(e.getKey()); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(componentsUtils.getResponseFormat(e.getValue(), "Consumer name")) + .thenReturn(new ResponseFormat()); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isRight()); + } + } + @Test + public void testCreateConsumer_givenInvalidConsumerPasswords_thenReturnsError() { + Map<String, ActionStatus> invalidPasswordResults = new HashMap<>(); + invalidPasswordResults.put(null, ActionStatus.MISSING_DATA); + invalidPasswordResults.put(RandomStringUtils.random(64, '*' ), ActionStatus.INVALID_CONTENT_PARAM); + invalidPasswordResults.put("password", ActionStatus.INVALID_LENGTH); + for(Map.Entry<String, ActionStatus> e: invalidPasswordResults.entrySet()){ + consumer.setConsumerName("_marvel"); + consumer.setConsumerPassword(e.getKey()); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(componentsUtils.getResponseFormat(e.getValue(), "Consumer password")) + .thenReturn(new ResponseFormat()); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isRight()); + } + } - @Test - public void testGetConsumer() throws Exception { - ConsumerBusinessLogic testSubject; - String consumerId = ""; - User user = null; - Either<ConsumerDefinition, ResponseFormat> result; + public void testCreateConsumer_givenInvalidConsumerSalts_thenReturnsError() { + consumer.setConsumerPassword(RandomStringUtils.random(64, true,true)); + Map<String, ActionStatus> invalidPasswordSalts = new HashMap<>(); + invalidPasswordSalts.put(null, ActionStatus.MISSING_DATA); + invalidPasswordSalts.put(RandomStringUtils.random(32, "*" ), ActionStatus.INVALID_CONTENT_PARAM); + invalidPasswordSalts.put("password", ActionStatus.INVALID_LENGTH); + for(Map.Entry<String, ActionStatus> e: invalidPasswordSalts.entrySet()){ + consumer.setConsumerName("_marvel"); + consumer.setConsumerSalt(e.getKey()); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(componentsUtils.getResponseFormat(e.getValue(), "Consumer salt")) + .thenReturn(new ResponseFormat()); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isRight()); + } + } - // test 1 - testSubject = createTestSubject(); - user = null; + @Test + public void testCreateConsumer_givenConsumerNotLocked_thenReturnsError() { + consumer.setConsumerName("_marvel"); + consumer.setConsumerPassword(RandomStringUtils.random(64, true,true)); + consumer.setConsumerSalt(RandomStringUtils.random(32, 'a')); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(iGraphLockOperation.lockComponent(anyString(), any(NodeTypeEnum.class))) + .thenReturn(StorageOperationStatus.GENERAL_ERROR); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isRight()); } - @Test - public void testGetConsumer_1() throws Exception { - ConsumerBusinessLogic testSubject; - String consumerId = ""; - Either<ConsumerDefinition, ResponseFormat> result; + public void testCreateConsumer_givenUnableToCreateCredentials_thenReturnsError() { + ConsumerDataDefinition consumerDataDefinition = new ConsumerDataDefinition(); + consumerDataDefinition.setConsumerName("_marvel"); + consumerDataDefinition.setConsumerPassword(RandomStringUtils.random(64, true,true)); + consumerDataDefinition.setConsumerSalt(RandomStringUtils.random(32, 'a')); + ConsumerDefinition consumer = new ConsumerDefinition(consumerDataDefinition); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(iGraphLockOperation.lockComponent(anyString(), any(NodeTypeEnum.class))) + .thenReturn(StorageOperationStatus.OK); + Mockito.when(consumerOperation.getCredentials(anyString())) + .thenReturn(Either.right(StorageOperationStatus.OK)); + Mockito.when(consumerOperation.createCredentials(any(ConsumerData.class))) + .thenReturn(Either.right(StorageOperationStatus.USER_NOT_FOUND)); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isRight()); + } - // default test - testSubject = createTestSubject(); + @Test + public void testCreateConsumer_givenValidUserAndConsumer_thenReturnsConsumer() { + ConsumerDataDefinition consumerDataDefinition = new ConsumerDataDefinition(); + consumerDataDefinition.setConsumerName("_marvel"); + consumerDataDefinition.setConsumerPassword(RandomStringUtils.random(64, true,true)); + consumerDataDefinition.setConsumerSalt(RandomStringUtils.random(32, 'a')); + ConsumerDefinition consumer = new ConsumerDefinition(consumerDataDefinition); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(iGraphLockOperation.lockComponent(anyString(), any(NodeTypeEnum.class))) + .thenReturn(StorageOperationStatus.OK); + Mockito.when(consumerOperation.getCredentials(anyString())) + .thenReturn(Either.right(StorageOperationStatus.OK)); + Mockito.when(consumerOperation.createCredentials(any(ConsumerData.class))) + .thenReturn(Either.left(new ConsumerData(consumerDataDefinition))); + assertTrue(consumerBusinessLogic.createConsumer(user, consumer).isLeft()); } - @Test - public void testDeleteConsumer() throws Exception { - ConsumerBusinessLogic testSubject; - String consumerId = ""; - User user = null; - Either<ConsumerDefinition, ResponseFormat> result; + public void testGetConsumer_givenNullUser_thenReturnsError() { + Mockito.when(consumerOperation.getCredentials("marvel123")) + .thenReturn(Either.right(StorageOperationStatus.USER_NOT_FOUND)); + assertTrue(consumerBusinessLogic.getConsumer("marvel123", null).isRight()); + } - // default test - testSubject = createTestSubject(); + @Test + public void testGetConsumer_givenValidUserAndConsumerId_thenReturnsConsumer() { + Mockito.when(consumerOperation.getCredentials("marvel123")) + .thenReturn(Either.left(new ConsumerData())); + Mockito.when(consumerData.getConsumerDataDefinition()) + .thenReturn(consumerDataDefinition); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + assertTrue(consumerBusinessLogic.getConsumer("marvel123", user).isLeft()); } - @Test - public void testUpdateConsumer() throws Exception { - ConsumerBusinessLogic testSubject; - ConsumerDefinition consumer = null; - User modifier = null; - boolean isCreateRequest = false; - Either<ConsumerDefinition, ResponseFormat> result; + public void testUpdateConsumer_givenValidConsumer_thenReturnsUpdatedConsumer() { + ConsumerDefinition updatedConsumer = new ConsumerDefinition(consumerDataDefinition); + updatedConsumer.setConsumerName("marvel2"); + ConsumerDataDefinition updatedConsumerDataDef = new ConsumerDataDefinition(); + updatedConsumerDataDef.setConsumerName("marvel2"); + ConsumerData consumerData = new ConsumerData(updatedConsumerDataDef); + Mockito.when(consumerOperation.updateCredentials(any(ConsumerData.class))) + .thenReturn(Either.left(consumerData)); + assertEquals(updatedConsumer.getConsumerName(), consumerBusinessLogic.updateConsumer(consumer).left().value().getConsumerName()); + } - // default test - testSubject = createTestSubject(); + @Test + public void testUpdateConsumer_givenUpdateFailure_thenReturnsError() { + Mockito.when(consumerOperation.updateCredentials(any(ConsumerData.class))) + .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR)); + assertTrue(consumerBusinessLogic.updateConsumer(consumer).isRight()); } - + @Test + public void testDeleteConsumer_givenValidUserAndConsumerId_thenReturnsSuccessful() { + ConsumerData consumerData = new ConsumerData(new ConsumerDataDefinition()); + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(consumerOperation.deleteCredentials("marvel123")) + .thenReturn(Either.left(consumerData)); + assertTrue(consumerBusinessLogic.deleteConsumer("marvel123", user).isLeft()); + } + @Test + public void testDeleteConsumer_givenInvalidUser_thenReturnsError() { + Mockito.when(iUserBusinessLogic.getUser(user.getUserId(), false)) + .thenReturn(Either.left(user)); + Mockito.when(consumerOperation.deleteCredentials("marvel123")) + .thenReturn(Either.right(StorageOperationStatus.USER_NOT_FOUND)); + assertTrue(consumerBusinessLogic.deleteConsumer("marvel123", user).isRight()); + } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogicTest.java new file mode 100644 index 0000000000..c2dacb6d7d --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogicTest.java @@ -0,0 +1,87 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.impl.MonitoringDao; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.common.monitoring.MonitoringEvent; +import org.openecomp.sdc.exception.ResponseFormat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +public class MonitoringBusinessLogicTest { + + private MonitoringEvent event; + + @InjectMocks + MonitoringBusinessLogic monitoringBusinessLogic; + + @Mock + private MonitoringDao monitoringDao; + + @Mock + private ComponentsUtils componentsUtils; + + @Before + public void setUp() throws Exception { + monitoringBusinessLogic = new MonitoringBusinessLogic(); + MockitoAnnotations.initMocks(this); + event = new MonitoringEvent(); + } + + @Test + public void testLogMonitoringEvent_returnsSuccessful() { + Mockito.when(monitoringDao.addRecord(any(MonitoringEvent.class))).thenReturn(ActionStatus.OK); + assertTrue(monitoringBusinessLogic.logMonitoringEvent(event).isLeft()); + } + + @Test + public void testLogMonitoringEvent_returnsError() { + Mockito.when(monitoringDao.addRecord(any(MonitoringEvent.class))).thenReturn(ActionStatus.GENERAL_ERROR); + Mockito.when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); + assertTrue(monitoringBusinessLogic.logMonitoringEvent(event).isRight()); + } + + @Test + public void testGetEsPort(){ + when(monitoringDao.getEsPort()).thenReturn("10"); + String port = monitoringBusinessLogic.getEsPort(); + assertEquals("10", port); + } + + @Test + public void testGetHost(){ + Mockito.when(monitoringDao.getEsHost()).thenReturn("['127.0.0.1', '[::1]']"); + assertEquals("127.0.0.1", monitoringBusinessLogic.getEsHost()); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java new file mode 100644 index 0000000000..7026325e13 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtilsTest.java @@ -0,0 +1,62 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.utils; + +import org.junit.Test; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo; +import org.openecomp.sdc.be.model.UploadNodeFilterInfo; +import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class CINodeFilterUtilsTest { + + private CINodeFilterUtils ciNodeFilterUtils; + + @Test + public void testNodeFilterDataDefinition(){ + ciNodeFilterUtils = new CINodeFilterUtils(); + UploadNodeFilterInfo uNodeFilterInfo = new UploadNodeFilterInfo(); + + UploadNodeFilterPropertyInfo propertyInfo = new UploadNodeFilterPropertyInfo(); + propertyInfo.setName("prop1"); + List<UploadNodeFilterPropertyInfo> properties = new ArrayList<>(); + properties.add(propertyInfo); + + UploadNodeFilterCapabilitiesInfo capabilitiesInfo = new UploadNodeFilterCapabilitiesInfo(); + capabilitiesInfo.setName("cap1"); + capabilitiesInfo.setProperties(properties); + + Map<String, UploadNodeFilterCapabilitiesInfo> capabilities = new HashMap<>(); + capabilities.put("test", capabilitiesInfo); + uNodeFilterInfo.setCapabilities(capabilities); + + CINodeFilterDataDefinition dataDefinition = ciNodeFilterUtils.getNodeFilterDataDefinition(uNodeFilterInfo, "id"); + assertEquals("id", dataDefinition.getID()); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CapabilityTypeImportUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CapabilityTypeImportUtilsTest.java new file mode 100644 index 0000000000..1c066db111 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/CapabilityTypeImportUtilsTest.java @@ -0,0 +1,69 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.utils; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.be.model.CapabilityTypeDefinition; +import java.util.Collections; + +import static org.junit.Assert.assertTrue; + +public class CapabilityTypeImportUtilsTest { + + private CapabilityTypeDefinition type1; + private CapabilityTypeDefinition type2; + + @Before + public void setUp(){ + type1 = new CapabilityTypeDefinition(); + type2 = new CapabilityTypeDefinition(); + } + + @Test + public void testGivenSameType_returnsTrue(){ + assertTrue(CapabilityTypeImportUtils.isCapabilityTypesEquals(type1, type1)); + } + + @Test + public void testGivenNullCapability_returnsFalse(){ + Assert.assertFalse(CapabilityTypeImportUtils.isCapabilityTypesEquals(type1,null)); + } + + @Test + public void testGivenEqualCapabilitiesWithParams_thenReturnsTrue(){ + updateCapabilities(type1); + updateCapabilities(type2); + assertTrue(CapabilityTypeImportUtils.isCapabilityTypesEquals(type1, type2)); + } + + private void updateCapabilities(CapabilityTypeDefinition type){ + type.setType("a"); + type.setVersion("1"); + type.setDerivedFrom("none"); + type.setValidSourceTypes(Collections.EMPTY_LIST); + type.setDescription("Testing capability types"); + type.setProperties(Collections.EMPTY_MAP); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilsTest.java new file mode 100644 index 0000000000..fea039ef27 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilsTest.java @@ -0,0 +1,59 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.utils; + +import org.junit.Before; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DirectivesUtilsTest { + + private List<String> directives; + + @Before + public void setup(){ + directives = new ArrayList<>(); + } + + @Test + public void testGivenValidDirectives_returnsTrue(){ + directives.add(DirectivesUtils.DIRECTIVE.SUBSTITUTABLE.toString()); + directives.add(DirectivesUtils.DIRECTIVE.SELECTABLE.toString()); + assertTrue(DirectivesUtils.isValid(directives)); + } + + @Test + public void testGivenEmptyDirectives_returnsTrue(){ + assertTrue(DirectivesUtils.isValid(directives)); + } + + @Test + public void testGivenInvalidDirectives_returnsFalse(){ + directives.add("Invalid"); + assertFalse(DirectivesUtils.isValid(directives)); + } +}
\ No newline at end of file |