Refactor the Model/Service/Resource/Widget hierarchy to improve code
readability.
Replace the configurable Boolean value for a Resource's model type with
a value from the existing ModelType enum.
Obtain the A&AI XML Model name (always resource or service) directly
from the Model class and not from the configured model type for the
Resource.
Change-Id: I1487d919392b34e4bf1314da8cd2805a9fbf96a3
Issue-ID: AAI-2212
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
this.csarHelper = csarHelper;
}
this.csarHelper = csarHelper;
}
- /**
- * Get or create the artifact description.
- *
- * @param model
- * the artifact model
- * @return the artifact model's description
- */
- public static String getArtifactDescription(Model model) {
- switch (model.getModelType()) {
- case SERVICE:
- return "AAI Service Model";
- case RESOURCE:
- return "AAI Resource Model";
- default:
- return model.getModelDescription();
- }
- }
-
/**
* Initializes the Widget to UUID mapping configuration.
*
/**
* Initializes the Widget to UUID mapping configuration.
*
* if the relation is a widget and there is no configuration defined for the relation's widget type
*/
public void addRelatedModel(final Model model, final Resource relation) throws XmlArtifactGenerationException {
* if the relation is a widget and there is no configuration defined for the relation's widget type
*/
public void addRelatedModel(final Model model, final Resource relation) throws XmlArtifactGenerationException {
- if (relation.isResource()) {
+ if (relation.getModelType() == ModelType.RESOURCE) {
model.addResource(relation);
} else {
model.addWidget(Widget.getWidget(relation.getWidgetType()));
model.addResource(relation);
} else {
model.addWidget(Widget.getWidget(relation.getWidgetType()));
memberModel.getClass().getSuperclass().getSimpleName(), memberModel.getClass(), nodeTypeName));
addRelatedModel(groupModel, memberModel);
memberModel.getClass().getSuperclass().getSimpleName(), memberModel.getClass(), nodeTypeName));
addRelatedModel(groupModel, memberModel);
- if (memberModel.isResource()) {
+ if (memberModel.getModelType() == ModelType.RESOURCE) {
resources.add(memberModel);
}
}
resources.add(memberModel);
}
}
if (resource.getWidgetType() == Type.L3_NET) {
// An l3-network inside a vf-module is treated as a Widget
if (resource.getWidgetType() == Type.L3_NET) {
// An l3-network inside a vf-module is treated as a Widget
- resource.setIsResource(false);
+ resource.setModelType(ModelType.WIDGET);
- if (!resource.isResource()) {
+ if (resource.getModelType() == ModelType.WIDGET) {
Widget widget = Widget.getWidget(resource.getWidgetType());
widget.addKey(member.getName());
// Add the widget element encountered to the Group model
Widget widget = Widget.getWidget(resource.getWidgetType());
widget.addKey(member.getName());
// Add the widget element encountered to the Group model
if (foundProvidingService) {
processProvidingService(resourceModel, resourceNode, nodeProperties);
if (foundProvidingService) {
processProvidingService(resourceModel, resourceNode, nodeProperties);
- } else if (resourceNode != null && resourceNode.isResource()
+ } else if (resourceNode != null && resourceNode.getModelType() == ModelType.RESOURCE
&& resourceNode.getWidgetType() != Widget.Type.L3_NET) {
if (metaData != null) {
resourceNode.populateModelIdentificationInformation(metaData.getAllProperties());
&& resourceNode.getWidgetType() != Widget.Type.L3_NET) {
if (metaData != null) {
resourceNode.populateModelIdentificationInformation(metaData.getAllProperties());
import org.onap.aai.babel.xml.generator.model.Service;
import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.model.Service;
import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
}
parser.addRelatedModel(serviceModel, model);
}
parser.addRelatedModel(serviceModel, model);
- if (model.isResource()) {
+ if (model.getModelType() == ModelType.RESOURCE) {
generateResourceModel(csarHelper, resources, parser, nodeTemplate);
}
} else {
generateResourceModel(csarHelper, resources, parser, nodeTemplate);
}
} else {
private String getArtifactLabel(Model model) {
StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
artifactName.append("-");
private String getArtifactLabel(Model model) {
StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
artifactName.append("-");
- artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append(model.getModelTypeName());
artifactName.append("-");
artifactName.append(hashCodeUuId(model.getModelNameVersionId()));
return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-");
artifactName.append("-");
artifactName.append(hashCodeUuId(model.getModelNameVersionId()));
return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-");
artifactName.append(truncatedArtifactName);
artifactName.append("-");
artifactName.append(truncatedArtifactName);
artifactName.append("-");
- artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append(model.getModelTypeName());
artifactName.append("-");
artifactName.append(model.getModelVersion());
artifactName.append("-");
artifactName.append(model.getModelVersion());
* AAI model as string
* @return Generated {@link Artifact} model for the resource
*/
* AAI model as string
* @return Generated {@link Artifact} model for the resource
*/
- private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
+ private Artifact getResourceArtifact(Resource resourceModel, String aaiResourceModel) {
final String resourceArtifactLabel = getArtifactLabel(resourceModel);
MDC.put(MDC_PARAM_MODEL_INFO, resourceModel.getModelName() + "," + resourceArtifactLabel);
final byte[] bytes = aaiResourceModel.getBytes();
final String resourceArtifactLabel = getArtifactLabel(resourceModel);
MDC.put(MDC_PARAM_MODEL_INFO, resourceModel.getModelName() + "," + resourceArtifactLabel);
final byte[] bytes = aaiResourceModel.getBytes();
GeneratorUtil.checkSum(bytes), GeneratorUtil.encode(bytes));
artifact.setName(getArtifactName(resourceModel));
artifact.setLabel(resourceArtifactLabel);
GeneratorUtil.checkSum(bytes), GeneratorUtil.encode(bytes));
artifact.setName(getArtifactName(resourceModel));
artifact.setLabel(resourceArtifactLabel);
- artifact.setDescription(ArtifactGeneratorToscaParser.getArtifactDescription(resourceModel));
+ artifact.setDescription("AAI Resource Model");
String serviceArtifactLabel = getArtifactLabel(serviceModel);
artifact.setName(serviceArtifactName);
artifact.setLabel(serviceArtifactLabel);
String serviceArtifactLabel = getArtifactLabel(serviceModel);
artifact.setName(serviceArtifactName);
artifact.setLabel(serviceArtifactLabel);
- String description = ArtifactGeneratorToscaParser.getArtifactDescription(serviceModel);
- artifact.setDescription(description);
+ artifact.setDescription("AAI Service Model");
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
modelVer.setModelElements(new ModelElements());
ModelElements modelElements = modelVer.getModelElements();
// Populate basic model details
modelVer.setModelElements(new ModelElements());
ModelElements modelElements = modelVer.getModelElements();
// Populate basic model details
- aaiServiceModel.setModelType(service.getModelType().name().toLowerCase()); // Using enum name as model type
+ aaiServiceModel.setModelType(service.getModelTypeName());
List<ModelElement> modelElementList = modelElements.getModelElement();
// Add service base widget model element
List<ModelElement> modelElementList = modelElements.getModelElement();
// Add service base widget model element
modelVer.setModelVersionId(resource.getModelNameVersionId());
modelVer.setModelElements(new ModelElements());
ModelElements modelElements = modelVer.getModelElements();
modelVer.setModelVersionId(resource.getModelNameVersionId());
modelVer.setModelElements(new ModelElements());
ModelElements modelElements = modelVer.getModelElements();
- aaiResourceModel.setModelType(resource.getModelType().name().toLowerCase()); // Using enum name as model type
+ aaiResourceModel.setModelType(resource.getModelTypeName());
List<ModelElement> modelElementList = modelElements.getModelElement();
// Add resource base widget model element
List<ModelElement> modelElementList = modelElements.getModelElement();
// Add resource base widget model element
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* 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.aai.babel.xml.generator.data;
package org.onap.aai.babel.xml.generator.data;
+import com.google.common.base.Enums;
+import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.types.ModelType;
public class WidgetConfigurationUtil {
public class WidgetConfigurationUtil {
- public static void setWidgetMappings(List<WidgetMapping> mappings) {
+ public static void setWidgetMappings(List<WidgetMapping> mappings) throws IOException {
for (WidgetMapping mapping : mappings) {
for (WidgetMapping mapping : mappings) {
- if (mapping.prefix == null || mapping.widget == null) {
- throw new IllegalArgumentException("Incomplete widget mapping specified: " + mapping);
+ ModelType modelType = Optional.ofNullable(mapping.type).map(String::toUpperCase)
+ .map(s -> Enums.getIfPresent(ModelType.class, s).orNull()).orElse(null);
+ if (mapping.prefix == null || mapping.widget == null || modelType == null) {
+ throw new IOException("Invalid widget mapping specified: " + mapping);
}
Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
}
Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
- resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
+ resource.setModelType(modelType);
typeToResource.put(mapping.prefix, resource);
}
}
typeToResource.put(mapping.prefix, resource);
}
}
package org.onap.aai.babel.xml.generator.data;
package org.onap.aai.babel.xml.generator.data;
public class WidgetMapping {
String prefix;
String type = "resource"; // Default type is Resource (not Widget)
String widget;
boolean deleteFlag = true;
public class WidgetMapping {
String prefix;
String type = "resource"; // Default type is Resource (not Widget)
String widget;
boolean deleteFlag = true;
- Map<String, Object> properties;
public void setType(String type) {
this.type = type;
public void setType(String type) {
this.type = type;
@Override
public String toString() {
return "WidgetMapping [prefix=" + prefix + ", type=" + type + ", widget=" + widget + ", deleteFlag="
@Override
public String toString() {
return "WidgetMapping [prefix=" + prefix + ", type=" + type + ", widget=" + widget + ", deleteFlag="
- + deleteFlag + ", properties=" + properties + "]";
import java.util.Set;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import java.util.Set;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
-import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
-import org.onap.aai.babel.xml.generator.types.ModelType;
public abstract class Model {
public abstract class Model {
- public abstract boolean addResource(Resource resource);
-
public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
public abstract Widget.Type getWidgetType();
public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
public abstract Widget.Type getWidgetType();
- public abstract Map<String, Object> getProperties();
+ public abstract String getModelTypeName();
- public abstract boolean isResource();
+ public boolean addResource(Resource resource) {
+ return resources.add(resource);
+ }
}
public String getModelId() {
}
public String getModelId() {
}
public String getModelNameVersionId() {
}
public String getModelNameVersionId() {
return modelNameVersionId;
}
return modelNameVersionId;
}
- /**
- * Gets model type.
- *
- * @return the model type
- */
- public ModelType getModelType() {
- if (this instanceof Service) {
- return ModelType.SERVICE;
- } else if (this instanceof Resource) {
- return ModelType.RESOURCE;
- } else if (this instanceof Widget) {
- return ModelType.WIDGET;
- } else {
- return null;
- }
- }
-
/**
* Gets widget version id.
*
/**
* Gets widget version id.
*
- private void checkSupported() {
- if (this instanceof Widget) {
- throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
- }
+ @Override
+ public String toString() {
+ return "Model [type=" + getModelTypeName() + ", name=" + getModelName() + "]";
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.Map;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import java.util.Map;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.types.ModelType;
public class Resource extends Model {
public class Resource extends Model {
private Type type;
private boolean deleteFlag;
private Type type;
private boolean deleteFlag;
- private boolean isResource = true;
+ private ModelType modelType = ModelType.RESOURCE;
private Map<String, Object> properties = Collections.emptyMap();
Widget vserver = null;
private Map<String, Object> properties = Collections.emptyMap();
Widget vserver = null;
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
public Map<String, Object> getProperties() {
return properties;
}
public Map<String, Object> getProperties() {
return properties;
}
-
- public void setIsResource(boolean isResource) {
- this.isResource = isResource;
+
+ public void setModelType(ModelType type) {
+ this.modelType = type;
-
- @Override
- public boolean isResource() {
- return isResource;
+
+ public ModelType getModelType() {
+ return modelType;
public void setMembers(List<String> members) {
this.members = members;
}
public void setMembers(List<String> members) {
this.members = members;
}
- @Override
- public boolean addResource(Resource resource) {
- return resources.add(resource);
- }
-
return widgets.add(widget);
}
}
return widgets.add(widget);
}
}
public Type getWidgetType() {
return type;
}
public Type getWidgetType() {
return type;
}
+
+ public String getModelTypeName() {
+ return "resource";
+ }
@Override
public String toString() {
@Override
public String toString() {
- return "Widget type " + getWidgetType() + ", isResource=" + isResource() + ", deleteFlag=" + deleteFlag;
+ return "Resource [widget type=" + getWidgetType() + ", deleteFlag=" + deleteFlag + ", modelType=" + modelType
+ + ", properties=" + properties + ", vserver=" + vserver + ", addlintf=" + addlintf + ", addvolume="
+ + addvolume + ", members=" + members + "]";
}
private void addVolumeWidget(Widget widget) {
}
private void addVolumeWidget(Widget widget) {
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ================================================================================
* 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.aai.babel.xml.generator.model;
package org.onap.aai.babel.xml.generator.model;
-import java.util.Collections;
-import java.util.Map;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
public class Service extends Model {
import org.onap.aai.babel.xml.generator.model.Widget.Type;
public class Service extends Model {
- @Override
- public boolean addResource(Resource resource) {
- return resources.add(resource);
- }
-
@Override
public boolean addWidget(Widget widget) {
return widgets.add(widget);
@Override
public boolean addWidget(Widget widget) {
return widgets.add(widget);
- @Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isResource() {
- return false;
+ public String getModelTypeName() {
+ return "service";
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import java.util.Properties;
import java.util.Set;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
* Copy Constructor.
*
* @param baseWidget
* Copy Constructor.
*
* @param baseWidget
- * @throws XmlArtifactGenerationException
+ * @throws XmlArtifactGenerationException
*/
public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
*/
public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
* @param type
* the type
* @return a new widget of the specified type
* @param type
* the type
* @return a new widget of the specified type
- * @throws XmlArtifactGenerationException
+ * @throws XmlArtifactGenerationException
* if there is no configuration defined for the specified type
*/
public static Widget getWidget(Type type) throws XmlArtifactGenerationException {
* if there is no configuration defined for the specified type
*/
public static Widget getWidget(Type type) throws XmlArtifactGenerationException {
- @Override
- public boolean isResource() {
- return false;
- }
-
public String getId() {
String id = WidgetConfigurationUtil.getConfig()
.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
public String getId() {
String id = WidgetConfigurationUtil.getConfig()
.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
- @Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
@Override
public String toString() {
return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
@Override
public String toString() {
return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
public boolean getDeleteFlag() {
return deleteFlag;
}
public boolean getDeleteFlag() {
return deleteFlag;
}
+
+ @Override
+ public String getModelTypeName() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public String getModelId() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public String getModelNameVersionId() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
- * Initialise the Artifact Generator Widget Mapping config with incomplete data (no type).
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
+ *
+ * @throws IOException
- @Test(expected = IllegalArgumentException.class)
- public void testToscaMappingWithoutType() {
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutType() throws IOException {
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setType(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
/**
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setType(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
/**
- * Initialise the Artifact Generator Widget Mapping config with incomplete data (no widget name).
+ * Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
+ *
+ * @throws IOException
- @Test(expected = IllegalArgumentException.class)
- public void testToscaMappingWithoutWidget() {
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithInvalidType() throws IOException {
+ WidgetMapping invalidMapping = new WidgetMapping();
+ invalidMapping.setType("invalid");
+ WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+ }
+
+ /**
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
+ *
+ * @throws IOException
+ */
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutWidget() throws IOException {
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setWidget(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setWidget(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
/**
* Process a dummy Group object for a Service Resource.
*
/**
* Process a dummy Group object for a Service Resource.
*
import static org.junit.Assert.assertThat;
import java.io.IOException;
import static org.junit.Assert.assertThat;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
-import org.onap.aai.babel.xml.generator.types.ModelType;
/**
* Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
/**
* Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
*/
public class TestModel {
*/
public class TestModel {
- private Service serviceModel = new Service();
- private List<Resource> resourceModels =
- Arrays.asList(new Resource(Type.CR, true), new Resource(Type.INSTANCE_GROUP, true));
private Widget widgetModel = new Widget(Type.OAM_NETWORK, "oam-network", true);
private Model anonymousModel;
private Widget widgetModel = new Widget(Type.OAM_NETWORK, "oam-network", true);
private Model anonymousModel;
utils.loadWidgetToUuidMappings();
anonymousModel = new Model() {
utils.loadWidgetToUuidMappings();
anonymousModel = new Model() {
- @Override
- public boolean addResource(Resource resource) {
- return false;
- }
-
@Override
public boolean addWidget(Widget resource) {
return false;
@Override
public boolean addWidget(Widget resource) {
return false;
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isResource() {
- return false;
+ public String getModelTypeName() {
+ return null;
assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
}
assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
}
- @Test
- public void testGetModelType() {
- assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
- for (Resource resourceModel : resourceModels) {
- assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
- }
- assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
- assertThat(anonymousModel.getModelType(), is(nullValue()));
- }
-
@Test
public void testGetModelNameVersionId() {
assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
@Test
public void testGetModelNameVersionId() {
assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
public void testGetModelNameVersionIdIsUnsupported() {
assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
public void testGetModelNameVersionIdIsUnsupported() {
assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
- assertThat(resourceModels.get(0).getModelType(), is(ModelType.RESOURCE));
- assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
- assertThat(anonymousModel.getModelType(), is(nullValue()));