/*- * ============LICENSE_START======================================================= * openECOMP : APP-C * ================================================================================ * 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========================================================= */ import org.openecomp.appc.exceptions.APPCException; import org.junit.Test; import org.openecomp.appc.adapter.netconf.OperationalStateValidator; import org.openecomp.appc.adapter.netconf.OperationalStateValidatorFactory; import org.openecomp.appc.adapter.netconf.VnfType; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; public class OperationalStateValidatorTest { @Test public void testVNFValidResponse() { String validResponse = "\n" + "\n" + " \n" + " \n" + " 1\n" + " \n" + " 1\n" + " \n" + " 1\n" + " \n" + " 1\n" + " ENABLED\n" + " \n" + " processor_0_5\n" + " ENABLED\n" + " \n" + " \n" + " processor_0_7\n" + " ENABLED\n" + " \n" + " \n" + " \n" + " SC-1\n" + " ENABLED\n" + " \n" + " \n" + " SC-2\n" + " ENABLED\n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); assertValidResponse(validResponse, operationalStateValidator); } void assertInvalidResponse(String response, OperationalStateValidator operationalStateValidator) { try { operationalStateValidator.validateResponse(response); fail("invalid resposne passed without exception!!!"); } catch (APPCException e) { assertNotNull(e.getMessage()); } } @Test public void testVNFInvalidResponses() { OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); assertInvalidResponse(null, operationalStateValidator); assertInvalidResponse("", operationalStateValidator); String response = ""; assertInvalidResponse(response, operationalStateValidator); response = "\n" + "\n" + ""; assertInvalidResponse(response, operationalStateValidator); response = "\n" + "\n" + " \n" + " \n" + " 1\n" + " \n" + " 1\n" + " \n" + " 1\n" + " \n" + " 1\n" + " ENABLED\n" + " \n" + " processor_0_5\n" + " ENABLED\n" + " \n" + " \n" + " processor_0_7\n" + " ENABLED\n" + " \n" + " \n" + " \n" + " SC-1\n" + " ENABLED\n" + " \n" + " \n" + " SC-2\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; assertInvalidResponse(response, operationalStateValidator); } void assertValidResponse(String response, OperationalStateValidator operationalStateValidator) { try { operationalStateValidator.validateResponse(response); } catch (APPCException e) { fail("Got unexpected exception. Validation failed. " + e.getMessage()); } } @Test public void testMockValidResponse() { String response = "valid"; OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator("mock"); assertValidResponse(response, operationalStateValidator); response = ""; assertValidResponse(response, operationalStateValidator); response = null; assertValidResponse(response, operationalStateValidator); } @Test public void testMockInValidResponse() { String response = "anything InValid anything.. "; OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.MOCK); assertInvalidResponse(response, operationalStateValidator); } @Test public void testGetOperationalStateValidatorForInValidVnfType() { try{ OperationalStateValidatorFactory.getOperationalStateValidator("wrongVnfType"); fail("invalid vnfType without exception!!!"); } catch (Exception e) { assertNotNull(e.getMessage()); } } @Test public void testGetOperationalStateValidatorForValidVnfType() { String vnfType = VnfType.VNF.name().toLowerCase(); assertGettingValidatorForValidVnf(vnfType); vnfType = VnfType.VNF.name().toUpperCase(); assertGettingValidatorForValidVnf(vnfType); vnfType = VnfType.MOCK.name().toLowerCase(); assertGettingValidatorForValidVnf(vnfType); vnfType = VnfType.MOCK.name().toUpperCase(); assertGettingValidatorForValidVnf(vnfType); } void assertGettingValidatorForValidVnf(String vnfType) { try{ OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(vnfType); assertNotNull(operationalStateValidator); } catch (Exception e) { fail("valid vnfType throw exception!!!"); } } }