From 375082572741a5c20059d10ccefb682c7cc44e54 Mon Sep 17 00:00:00 2001 From: Lathishbabu Ganesan Date: Wed, 27 Feb 2019 09:29:34 -0500 Subject: Added test cases for Sequence Generator class Increased the code coverage from 0% to 100% Issue-ID: APPC-1457 Change-Id: Id71298cb482a1c9ca00c3ced9685087e56c249ca Signed-off-by: Lathishbabu Ganesan --- .../TestSequenceGeneratorDBServices.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/dbservices/TestSequenceGeneratorDBServices.java diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/dbservices/TestSequenceGeneratorDBServices.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/dbservices/TestSequenceGeneratorDBServices.java new file mode 100644 index 000000000..3328ccde1 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/onap/appc/seqgen/dbservices/TestSequenceGeneratorDBServices.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * 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========================================================= + */ + +package org.onap.appc.seqgen.dbservices; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; + +public class TestSequenceGeneratorDBServices { + + private SequenceGeneratorDBServices sequenceGeneratorDBServices; + private SvcLogicContext localContext; + private SvcLogicResource serviceLogic; + + @Before + public void setUp() { + localContext = new SvcLogicContext(); + localContext.setAttribute("artifact-content", "artifact"); + sequenceGeneratorDBServices = new SequenceGeneratorDBServices(); + serviceLogic = Mockito.mock(SvcLogicResource.class); + Whitebox.setInternalState(sequenceGeneratorDBServices, "serviceLogic", serviceLogic); + } + + @Test + public void testGetOutputPayloadTemplate() throws SvcLogicException { + when(serviceLogic.query(eq("SQL"), eq(false), eq(null), anyString(), eq(null), eq(null), eq(localContext))) + .thenReturn(QueryStatus.SUCCESS); + assertEquals("artifact", sequenceGeneratorDBServices.getOutputPayloadTemplate(localContext)); + } + + @Test(expected = SvcLogicException.class) + public void testGetOutputPayloadTemplateException() throws SvcLogicException { + when(serviceLogic.query(eq("SQL"), eq(false), eq(null), anyString(), eq(null), eq(null), eq(localContext))) + .thenReturn(QueryStatus.FAILURE); + sequenceGeneratorDBServices.getOutputPayloadTemplate(localContext); + } + + @Test(expected = SvcLogicException.class) + public void testGetOutputPayloadTemplateFailure() throws SvcLogicException { + String query = + "select artifact_content from asdc_artifacts where artifact_name = $artifactName and internal_version = $maxInternalVersion "; + when(serviceLogic.query("SQL", false, null, query, null, null, localContext)).thenReturn(QueryStatus.FAILURE); + sequenceGeneratorDBServices.getOutputPayloadTemplate(localContext); + } + + @Test + public void testGetOutputPayloadTemplateNullContext() throws SvcLogicException { + assertNull(sequenceGeneratorDBServices.getOutputPayloadTemplate(null)); + } + + @Test + public void testInitialise() throws SvcLogicException { + assertNotNull(SequenceGeneratorDBServices.initialise()); + } + +} -- cgit 1.2.3-korg