* Yaml/String
*/
@Service
-public abstract class BlueprintService {
+public class BlueprintService {
@Autowired
protected FixesService fixesService;
* * org.onap.dcae
* * ================================================================================
* * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * * Copyright (c) 2020 Nokia. 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.
package org.onap.blueprintgenerator;
+
+import static java.lang.System.exit;
+
import org.onap.blueprintgenerator.model.base.Blueprint;
import org.onap.blueprintgenerator.model.common.Input;
import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec;
-import org.onap.blueprintgenerator.service.OnapBlueprintService;
+import org.onap.blueprintgenerator.service.BlueprintCreatorService;
+import org.onap.blueprintgenerator.service.base.BlueprintService;
import org.onap.blueprintgenerator.service.common.CommonUtils;
import org.onap.blueprintgenerator.service.common.ComponentSpecService;
-import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService;
import org.onap.policycreate.service.PolicyModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
-import static java.lang.System.exit;
-
/**
* @author : Ravi Mantena
* @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP - Blueprint Generator Main
private CommonUtils onapCommonUtils;
@Autowired
- private OnapBlueprintService onapBlueprintService;
+ private BlueprintCreatorService blueprintCreatorService;
@Autowired
- private DmaapBlueprintService dmaapBlueprintService;
+ private BlueprintService blueprintService;
/**
* Main Application to run BPGen to generate Policies/Blueprint based on Input Arguments values
componentSpec.getParameters(), input.getOutputPath());
} else {
Input input = onapCommonUtils.parseInputs(args);
- OnapComponentSpec onapComponentSpec =
- onapComponentSpecService
- .createComponentSpecFromFile(input.getComponentSpecPath());
- if (input.getBpType().equals("o")) {
- Blueprint blueprint = onapBlueprintService
- .createBlueprint(onapComponentSpec, input);
- onapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
- System.out.println(
- onapBlueprintService
- .blueprintToString(onapComponentSpec, blueprint, input));
- } else if (input.getBpType().equals("d")) {
- Blueprint blueprint = dmaapBlueprintService
- .createBlueprint(onapComponentSpec, input);
- dmaapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
- System.out.println(
- dmaapBlueprintService
- .blueprintToString(onapComponentSpec, blueprint, input));
- }
+ OnapComponentSpec onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
+ Blueprint blueprint = blueprintCreatorService.createBlueprint(onapComponentSpec, input);
+ blueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
+ System.out.println(blueprintService.blueprintToString(onapComponentSpec, blueprint, input));
}
}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * org.onap.dcae
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. 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=========================================================
+ */
+
+package org.onap.blueprintgenerator.service;
+
+import org.onap.blueprintgenerator.model.base.Blueprint;
+import org.onap.blueprintgenerator.model.common.Input;
+import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
+import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintCreatorService;
+import org.onap.blueprintgenerator.service.onap.OnapBlueprintCreatorService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author : Remigiusz Janeczek
+ * @date 12/17/2020 Application: ONAP - Blueprint Generator Service to create ONAP and DMAAP Blueprints
+ */
+@Service
+public class BlueprintCreatorService {
+
+ private final OnapBlueprintCreatorService onapBlueprintCreatorService;
+
+ private final DmaapBlueprintCreatorService dmaapBlueprintCreatorService;
+
+ @Autowired
+ public BlueprintCreatorService(OnapBlueprintCreatorService onapBlueprintCreatorService,
+ DmaapBlueprintCreatorService dmaapBlueprintCreatorService) {
+ this.onapBlueprintCreatorService = onapBlueprintCreatorService;
+ this.dmaapBlueprintCreatorService = dmaapBlueprintCreatorService;
+ }
+
+ /**
+ * Creates Blueprint from given OnapComponentSpec and Input objects if the input is json file or not
+ *
+ * @param componentSpec OnapComponentSpec object
+ * @param input Input object, needs to have bpType defined (either as "o" (ONAP Blueprint) or "d" (DMAAP
+ * Blueprint)
+ * @return blueprint generated from componentSpec and input
+ */
+ public Blueprint createBlueprint(OnapComponentSpec componentSpec, Input input) {
+ if (input.getBpType() == null) {
+ return null;
+ }
+ Blueprint blueprint = null;
+ if (input.getBpType().equals("o")) {
+ blueprint = onapBlueprintCreatorService.createBlueprint(componentSpec, input);
+ } else if (input.getBpType().equals("d")) {
+ blueprint = dmaapBlueprintCreatorService.createBlueprint(componentSpec, input);
+ }
+ return blueprint;
+ }
+
+}
* * org.onap.dcae
* * ================================================================================
* * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * * Copyright (c) 2020 Nokia. 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.
* @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create DMAAP Blueprint
*/
@Service
-public class DmaapBlueprintService extends BlueprintService {
+public class DmaapBlueprintCreatorService {
@Autowired
protected ImportsService importsService;
* * org.onap.dcae
* * ================================================================================
* * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * * Copyright (c) 2020 Nokia. 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.
*
*/
-package org.onap.blueprintgenerator.service;
+package org.onap.blueprintgenerator.service.onap;
import org.onap.blueprintgenerator.constants.Constants;
import org.onap.blueprintgenerator.exception.BlueprintException;
* @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create ONAP Blueprint
*/
@Service
-public class OnapBlueprintService extends BlueprintService {
+public class OnapBlueprintCreatorService {
@Autowired
private NodeService nodeService;
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * org.onap.dcae
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. 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=========================================================
+ */
+
+package org.onap.blueprintgenerator.service;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.blueprintgenerator.model.base.Blueprint;
+import org.onap.blueprintgenerator.model.common.Input;
+import org.onap.blueprintgenerator.model.common.OnapBlueprint;
+import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
+import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintCreatorService;
+import org.onap.blueprintgenerator.service.onap.OnapBlueprintCreatorService;
+
+public class BlueprintCreatorServiceTest {
+
+ private static final String ONAP_BP_TYPE = "o";
+ private static final String DMAAP_BP_TYPE = "d";
+ private static final String INCORRECT_BP_TYPE = "z";
+
+ private OnapBlueprintCreatorService onapBlueprintCreatorService;
+ private DmaapBlueprintCreatorService dmaapBlueprintCreatorService;
+ private BlueprintCreatorService blueprintCreatorService;
+
+ @Before
+ public void setup() {
+ onapBlueprintCreatorService = mock(OnapBlueprintCreatorService.class);
+ dmaapBlueprintCreatorService = mock(DmaapBlueprintCreatorService.class);
+ blueprintCreatorService = new BlueprintCreatorService(onapBlueprintCreatorService,
+ dmaapBlueprintCreatorService);
+ }
+
+ @Test
+ public void shouldCreateOnapBlueprint() {
+ OnapComponentSpec cs = new OnapComponentSpec();
+ Input input = new Input();
+ input.setBpType(ONAP_BP_TYPE);
+ when(onapBlueprintCreatorService.createBlueprint(any(), any())).thenReturn(new OnapBlueprint());
+
+ Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input);
+
+ verify(onapBlueprintCreatorService, times(1)).createBlueprint(cs, input);
+ verify(onapBlueprintCreatorService, times(1)).createBlueprint(cs, input);
+ verifyNoInteractions(dmaapBlueprintCreatorService);
+ assertNotNull(blueprint);
+ }
+
+ @Test
+ public void shouldCreateDmaapBlueprint() {
+ OnapComponentSpec cs = new OnapComponentSpec();
+ Input input = new Input();
+ input.setBpType(DMAAP_BP_TYPE);
+ when(dmaapBlueprintCreatorService.createBlueprint(any(), any())).thenReturn(new OnapBlueprint());
+
+ Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input);
+
+ verify(dmaapBlueprintCreatorService, times(1)).createBlueprint(cs, input);
+ verify(dmaapBlueprintCreatorService, times(1)).createBlueprint(cs, input);
+ verifyNoInteractions(onapBlueprintCreatorService);
+ assertNotNull(blueprint);
+ }
+
+ @Test
+ public void shouldReturnNullWhenBpTypeNotDefined(){
+ OnapComponentSpec cs = new OnapComponentSpec();
+ Input input = new Input();
+
+ Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input);
+
+ verifyNoInteractions(onapBlueprintCreatorService);
+ verifyNoInteractions(dmaapBlueprintCreatorService);
+ assertNull(blueprint);
+ }
+
+ @Test
+ public void shouldReturnNullWhenBpTypeIncorrect(){
+ OnapComponentSpec cs = new OnapComponentSpec();
+ Input input = new Input();
+ input.setBpType(INCORRECT_BP_TYPE);
+
+ Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input);
+
+ verifyNoInteractions(onapBlueprintCreatorService);
+ verifyNoInteractions(dmaapBlueprintCreatorService);
+ assertNull(blueprint);
+ }
+
+}
@RunWith(Suite.class)
@Suite.SuiteClasses({
OnapComponentSpecTest.class,
- OnapBlueprintServiceTest.class,
+ OnapBlueprintCreatorServiceTest.class,
ExternalCertificateParametersFactoryServiceTest.class /*, BlueprintJarComparatorTest.class*/
})
public class BlueprintGeneratorTestSuite {
* * org.onap.dcae
* * ================================================================================
* * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * * Copyright (c) 2020 Nokia. 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.
package org.onap.blueprintgenerator.test;
-import org.onap.blueprintgenerator.BlueprintGeneratorMainApplication;
-import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
-import org.onap.blueprintgenerator.service.OnapBlueprintService;
-import org.onap.blueprintgenerator.service.common.ComponentSpecService;
-import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Ignore;
import org.junit.runner.RunWith;
+import org.onap.blueprintgenerator.BlueprintGeneratorMainApplication;
+import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
+import org.onap.blueprintgenerator.service.BlueprintCreatorService;
+import org.onap.blueprintgenerator.service.base.BlueprintService;
+import org.onap.blueprintgenerator.service.common.ComponentSpecService;
+import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintCreatorService;
+import org.onap.blueprintgenerator.service.onap.OnapBlueprintCreatorService;
import org.onap.policycreate.service.PolicyModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
protected ComponentSpecService onapComponentSpecService;
@Autowired
- protected DmaapBlueprintService dmaapBlueprintService;
+ protected DmaapBlueprintCreatorService dmaapBlueprintCreatorService;
+
+ @Autowired
+ protected OnapBlueprintCreatorService onapBlueprintCreatorService;
+
+ @Autowired
+ protected BlueprintCreatorService blueprintCreatorService;
@Autowired
- protected OnapBlueprintService onapBlueprintService;
+ protected BlueprintService blueprintService;
@Autowired
protected PolicyModelService policyModelService;
* * org.onap.dcae
* * ================================================================================
* * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * * Copyright (c) 2020 Nokia. 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.
package org.onap.blueprintgenerator.test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
-import org.onap.blueprintgenerator.constants.Constants;
-import org.onap.blueprintgenerator.model.common.Input;
-import org.onap.blueprintgenerator.model.common.Node;
-import org.onap.blueprintgenerator.model.common.OnapBlueprint;
-import org.onap.blueprintgenerator.model.common.Properties;
-import org.junit.Test;
-import org.junit.jupiter.api.DisplayName;
-import picocli.CommandLine;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.io.PrintStream;
import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertArrayEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import org.junit.Test;
+import org.junit.jupiter.api.DisplayName;
+import org.onap.blueprintgenerator.constants.Constants;
+import org.onap.blueprintgenerator.model.common.Input;
+import org.onap.blueprintgenerator.model.common.Node;
+import org.onap.blueprintgenerator.model.common.OnapBlueprint;
+import org.onap.blueprintgenerator.model.common.Properties;
/**
* @author : Ravi Mantena
* @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and
* DMAAP
*/
-public class OnapBlueprintServiceTest extends BlueprintGeneratorTests {
+
+
+public class OnapBlueprintCreatorServiceTest extends BlueprintGeneratorTests {
private String outputfilesPath =
Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString();
assertNotNull(
"K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec);
- OnapBlueprint onapBlueprint = onapBlueprintService
- .createBlueprint(onapComponentSpec, input);
- onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
- System.out.println(
- onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
+ OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
+ blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
+ System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
onapTestUtils.verifyToscaDefVersion(
"Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
"K8s Blueprint for Service Name Override with Import File Component Spec is NULL",
onapComponentSpec);
- OnapBlueprint onapBlueprint = onapBlueprintService
- .createBlueprint(onapComponentSpec, input);
+ OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
onapTestUtils.verifyToscaDefVersion(
"Service Name Override with Import File K8s", onapBlueprint,
onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
- OnapBlueprint onapBlueprint = dmaapBlueprintService
- .createBlueprint(onapComponentSpec, input);
- onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
+ OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
+ blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
}
/**
onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec);
- OnapBlueprint onapBlueprint = dmaapBlueprintService
- .createBlueprint(onapComponentSpec, input);
- onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
- System.out.println(
- onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
+ OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
+ blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input);
+ System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input));
policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models");
assertNotNull(
"K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec);
- OnapBlueprint onapBlueprint = dmaapBlueprintService
- .createBlueprint(onapComponentSpec, input);
+ OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
onapTestUtils.verifyToscaDefVersion(
"DMAAP with Import File K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION);
private OnapBlueprint createBlueprintFromFile(String path) {
onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(path);
Input input = onapTestUtils.getInput(path, "", "", "", "o", "");
- OnapBlueprint onapBlueprint = onapBlueprintService
- .createBlueprint(onapComponentSpec, input);
+ OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input);
return onapBlueprint;
}
}