-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
import java.util.concurrent.ThreadPoolExecutor;
public class RestHandlerService {
- private static RestHandlerService single_instance = null;
+ private static RestHandlerService singleInstance = null;
public ThreadPoolExecutor executor;
- // private constructor restricted to this class itself
private RestHandlerService() {
executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(50);
}
* @return single instance of RestHandlerService
*/
public static RestHandlerService getInstance() {
- if (single_instance == null) {
- single_instance = new RestHandlerService();
+ if (singleInstance == null) {
+ singleInstance = new RestHandlerService();
}
- return single_instance;
+ return singleInstance;
}
}
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
public abstract class QueryEngine {
- final protected GraphTraversalSource g;
+ protected final GraphTraversalSource g;
protected double dbTimeMsecs = 0;
/**
public abstract List<Path> findCousinsAsPath(Vertex start);
public abstract double getDBTimeMsecs();
-
}
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Vertex;
Logger logger = LoggerFactory.getLogger(MultiFormatMapper.class);
protected boolean isTree = false;
+ protected static final String PROPERTIES_KEY = "properties";
+ protected static final String NODE_TYPE_KEY = "node-type";
+
+ protected static final String RETURNED_EMPTY_JSONARRAY_MSG =
+ "Returned empty JsonArray - Could not populate nested json objects for wrapper: {}";
@Override
public Optional<JsonObject> formatObject(Object input)
if (ja.size() > 0) {
t.add("nodes", ja);
} else {
- logger.debug("Returned empty JsonArray - Could not populate nested json objects for wrapper: {}", nodeIdentifier);
+ logger.debug(RETURNED_EMPTY_JSONARRAY_MSG, nodeIdentifier);
}
return Optional.of(t);
t.add("results", ja);
return Optional.of(t);
} else {
- logger.debug("Returned empty JsonArray - Could not populate nested json objects for wrapper: {}", nodeIdentifier);
+ logger.debug(RETURNED_EMPTY_JSONARRAY_MSG, nodeIdentifier);
}
return Optional.empty();
if (ja.size() > 0) {
me.add(nodeIdentifier, ja);
} else {
- logger.debug("Returned empty JsonArray - Could not populate nested json objects for wrapper: {}", nodeIdentifier);
+ logger.debug(RETURNED_EMPTY_JSONARRAY_MSG, nodeIdentifier);
}
nodes.add(me);
}
if (properties == null)
return new HashMap<>();
- Map<String, Set<String>> filterPropertiesMap = new HashMap<>();
- for (String key : properties.keySet()) {
- if (!filterPropertiesMap.containsKey(key)) {
- Set<String> newSet = new HashSet<>();
- for (String currProperty : properties.get(key)) {
- currProperty = truncateApostrophes(currProperty);
- newSet.add(currProperty);
+ return properties.entrySet().stream()
+ .map(entry -> {
+ Set<String> newSet = entry.getValue().stream()
+ .map(this::truncateApostrophes)
+ .collect(Collectors.toSet());
+
+ return Pair.of(entry.getKey(), newSet);
}
- filterPropertiesMap.put(key, newSet);
- }
- }
- return filterPropertiesMap;
+ ).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
}
/**
* @param filterPropertiesMap
* @return
*/
- protected JsonObject getPropertyFilteredObject(Optional<JsonObject> obj, Map<String, Set<String>> filterPropertiesMap) {
- if (filterPropertiesMap == null || filterPropertiesMap.isEmpty()) {
- return obj.get();
- }
- JsonObject jsonObj = obj.get();
- JsonObject result = new JsonObject();
- if (jsonObj != null) {
- String nodeType = "";
- JsonObject properties = null;
- // clone object
- for (Map.Entry<String, JsonElement> mapEntry : jsonObj.entrySet()) {
- String key = mapEntry.getKey(); JsonElement value = mapEntry.getValue();
-
- // also, check if payload has node-type and properties fields
- if (key.equals("node-type") && value != null) {
- nodeType = value.getAsString();
- } else if (key.equals("properties") && value != null && value.isJsonObject()) {
- properties = value.getAsJsonObject();
+ protected JsonObject getPropertyFilteredObject(Optional<JsonObject> obj,
+ Map<String, Set<String>> filterPropertiesMap) {
+ return obj.map(
+ jsonObj -> {
+ if (filterPropertiesMap == null || filterPropertiesMap.isEmpty()) {
+ return jsonObj;
+ } else {
+ ImmutableTriple<JsonObject, Optional<String>, Optional<JsonObject>> triple =
+ cloneObjectAndExtractNodeTypeAndProperties(jsonObj);
+
+ JsonObject result = triple.left;
+ Optional<String> nodeType = triple.middle;
+ Optional<JsonObject> properties = triple.right;
+
+ // Filter current object based on it containing fields: "node-type" and "properties"
+ if (nodeType.isPresent() && properties.isPresent()) {
+ filterByNodeTypeAndProperties(result, nodeType.get(), properties.get(), filterPropertiesMap);
+ } else {
+ // filter current object based on the: key - nodeType & value - JsonObject of nodes properties
+ filterByJsonObj(result, jsonObj, filterPropertiesMap);
+ }
+
+ return result;
}
- result.add(key, value);
}
+ ).orElseGet(JsonObject::new);
+ }
- // Filter current object based on it containing fields: "node-type" and "properties"
- if (!nodeType.isEmpty() && properties != null) {
- filterByNodeTypeAndProperties(result, nodeType, properties, filterPropertiesMap);
- } else {
- // filter current object based on the: key - nodeType & value - JsonObject of nodes properties
- filterByJsonObj(result, jsonObj, filterPropertiesMap);
+ private ImmutableTriple<JsonObject, Optional<String>, Optional<JsonObject>> cloneObjectAndExtractNodeTypeAndProperties(
+ JsonObject jsonObj) {
+ JsonObject result = new JsonObject();
+ Optional<String> nodeType = Optional.empty();
+ Optional<JsonObject> properties = Optional.empty();
+
+ // clone object
+ for (Map.Entry<String, JsonElement> mapEntry : jsonObj.entrySet()) {
+ String key = mapEntry.getKey();
+ JsonElement value = mapEntry.getValue();
+
+ // also, check if payload has node-type and properties fields
+ if (key.equals(NODE_TYPE_KEY) && value != null) {
+ nodeType = Optional.of(value.getAsString());
+ } else if (key.equals(PROPERTIES_KEY) && value != null && value.isJsonObject()) {
+ properties = Optional.of(value.getAsJsonObject());
}
+ result.add(key, value);
}
- return result;
+
+ return ImmutableTriple.of(result, nodeType, properties);
}
/**
filteredProperties.add(property, properties.get(property));
}
}
- result.remove("properties");
- result.add("properties", filteredProperties);
+ result.remove(PROPERTIES_KEY);
+ result.add(PROPERTIES_KEY, filteredProperties);
}
return result;
}
}
for (Map.Entry<String, JsonElement> mapEntry : jsonObj.entrySet()) {
- String key = mapEntry.getKey(); JsonElement value = mapEntry.getValue();
+ String key = mapEntry.getKey();
+ JsonElement value = mapEntry.getValue();
JsonObject filteredProperties = new JsonObject();
if (value != null && value.isJsonObject() && filterPropertiesMap.containsKey(key)) {
JsonObject joProperties = value.getAsJsonObject();
* @param filterPropertiesMap
* @return
*/
- protected JsonObject filterProperties(Optional<JsonObject> properties, String nodeType, Map<String, Set<String>> filterPropertiesMap) {
- if (filterPropertiesMap == null || filterPropertiesMap.isEmpty()) {
- return properties.get();
- }
+ protected JsonObject filterProperties(Optional<JsonObject> properties, String nodeType,
+ Map<String, Set<String>> filterPropertiesMap) {
+ return properties.map(jo -> {
+ if (filterPropertiesMap == null || filterPropertiesMap.isEmpty()) {
+ return properties.get();
+ }
- JsonObject jo = properties.get();
- JsonObject result = new JsonObject();
- if (jo != null) {
+ JsonObject result = new JsonObject();
// clone the object
for (Map.Entry<String, JsonElement> mapEntry : jo.entrySet()) {
String key = mapEntry.getKey();
}
}
}
- }
- return result;
+ return result;
+ }).orElseGet(JsonObject::new);
}
@Override
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
}
@Test
- public void getRealtimeInstanceConnectionName() throws Exception {
+ public void getRealtimeInstanceConnectionName() {
JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
String connectionInstanceName =
@Ignore("Need to create schema specific to the test")
@Test
- public void checkIndexOfAliasedIndexedProps() throws Exception {
+ public void checkIndexOfAliasedIndexedProps() {
Set<String> aliasedIndexedProps = getAliasedIndexedProps();
JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
for (String aliasedIndexedProp : aliasedIndexedProps) {
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* as these keys are generated in a couple places, I made a class to contain that logic
*/
public class HbaseSaltPrefixer {
- private int NUM_REGION_BUCKETS = 3; // the number of hbase region servers per cluster
+ // the number of hbase region servers per cluster
+ private static int NUM_REGION_BUCKETS = 3;
private static class SingletonHolder {
private static final HbaseSaltPrefixer INSTANCE = new HbaseSaltPrefixer();
}
- /**
- * Instantiates a new hbase salt prefixer.
- */
private HbaseSaltPrefixer() {
}
- /**
- * Gets the single instance of HbaseSaltPrefixer.
- *
- * @return single instance of HbaseSaltPrefixer
- */
public static HbaseSaltPrefixer getInstance() {
return SingletonHolder.INSTANCE;
}
- /**
- * Prepend salt.
- *
- * @param key the key
- * @return the string
- */
public String prependSalt(String key) {
int salt = Math.abs(key.hashCode()) % NUM_REGION_BUCKETS;
return salt + "-" + key;
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
LoggingContext.elapsedTime(300, TimeUnit.MILLISECONDS);
assertEquals(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()), "300");
LoggingContext.init();
- assertTrue(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()) == null);
+ assertNull(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()));
}
@Test
public void stopWatchTest() {
assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
LoggingContext.clear();
- assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null);
+ assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
}
assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
LoggingContext.remove(LoggingContext.LoggingField.SERVICE_NAME.toString());
- assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null);
+ assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
}
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* 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.
public class ClientType {
public static final String AAI = "aai-rest-client";
+
+ private ClientType() {
+ }
}
package org.onap.aai.schemaif;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.onap.aai.schemaif.definitions.EdgeSchema;
import org.onap.aai.schemaif.definitions.VertexSchema;
+import java.util.Map;
+import java.util.Set;
+
public interface SchemaProvider {
-
+
/**
* Load the schema into memory
*/
- public void loadSchema() throws SchemaProviderException;
-
+ void loadSchema() throws SchemaProviderException;
+
/**
* Get the identifier for the more recent version of the schema
*
* @return The schema version identifier
*/
- public String getLatestSchemaVersion() throws SchemaProviderException;
-
+ String getLatestSchemaVersion() throws SchemaProviderException;
+
/**
* Get the schema definition for a vertex
*
* @param vertexName - Name of the vertex
* @param schemaVersion - Version of the schema to use
- *
+ *
* @return The vertex schema definition
*/
- public VertexSchema getVertexSchema(String vertexName, String schemaVersion) throws SchemaProviderException;
-
+ VertexSchema getVertexSchema(String vertexName, String schemaVersion) throws SchemaProviderException;
+
/**
* Get the schema definition for an edge
*
* @param edgeType - Type of the edge
* @param sourceVertex - The source vertex for the edge
* @param targetVertex - The target vertex for the edge
- * @param schemaVersion - Version of the schema to use
- *
+ * @param version - Version of the schema to use
+ *
* @return The edge schema definition
*/
- public EdgeSchema getEdgeSchema(String edgeType, String sourceVertex, String targetVertex, String version) throws SchemaProviderException;
+ EdgeSchema getEdgeSchema(String edgeType, String sourceVertex, String targetVertex, String version) throws SchemaProviderException;
/**
* Get the list of edge definitions which are adjacent to the given vertex
*
* @param vertexType - Type of the vertex
- * @param schemaVersion - Version of the schema to use
- *
+ * @param version - Version of the schema to use
+ *
* @return The list of edge schema definitions
*/
- public Set<EdgeSchema> getAdjacentEdgeSchema(String vertexType, String version) throws SchemaProviderException;
-
+ Set<EdgeSchema> getAdjacentEdgeSchema(String vertexType, String version) throws SchemaProviderException;
+
/**
* Get the list of edge definitions which are valid for the given source and target
*
* @param sourceType - Type of the source vertex
* @param targetType - Type of the target vertex
- * @param schemaVersion - Version of the schema to use
- *
+ * @param version - Version of the schema to use
+ *
* @return The list of edge schema definitions
*/
- public Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException;
+ Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException;
/**
* Get vertex map for a schema version
*
* @param schemaVersion - Version of the schema to use
- *
+ *
* @return The list of vertex types
*/
- public Map<String, VertexSchema> getVertexMap(String schemaVersion) throws SchemaProviderException;
-
+ Map<String, VertexSchema> getVertexMap(String schemaVersion) throws SchemaProviderException;
}
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
package org.onap.aai.schemaif.definitions.types;
-import org.onap.aai.schemaif.SchemaProviderException;
-
public abstract class DataType {
public enum Type {
- STRING,
+ STRING,
BOOL,
INT,
LONG,
MAP,
COMPLEX
}
-
- private Type type;
-
+
+ private final Type type;
+
public DataType(Type type) {
this.type = type;
}
public Type getType() {
return type;
}
-
+
public abstract Object validateValue(String value);
-
+
public String toString() {
return getType().toString();
}
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
*/
package org.onap.aai.schemaif.json;
-import org.onap.aai.schemaif.SchemaProviderException;
-import org.onap.aai.schemaif.json.definitions.JsonSchema;
-
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
+import org.onap.aai.schemaif.SchemaProviderException;
+import org.onap.aai.schemaif.json.definitions.JsonSchema;
public class SchemaServiceResponse {
public static final String SCHEMA_TYPE_OXM = "oxm";
public static final String SCHEMA_TYPE_JSON = "json";
-
+
private static final Gson gson = new GsonBuilder().create();
@SerializedName("schema-version")
private String version;
-
+
@SerializedName("schema-content")
private JsonSchema data;
-
+
public String getVersion() {
return version;
}
if (json == null || json.isEmpty()) {
throw new SchemaProviderException("Empty schema-service response");
}
-
+
return gson.fromJson(json, SchemaServiceResponse.class);
} catch (Exception ex) {
throw new SchemaProviderException("Invalid response from schema service: " + ex.getMessage());
}
}
-
}
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
OxmEdgeRulesLoader.loadModels();
OxmSchemaLoader.loadModels();
}
-
+
@Override
public String getLatestSchemaVersion() throws SchemaProviderException {
return OxmSchemaLoader.getLatestVersion();
if (edgeRule == null) {
return null;
}
-
+
FromOxmEdgeSchema es = new FromOxmEdgeSchema();
es.fromEdgeRule(edgeRule);
-
+
return es;
}
@Override
public Set<EdgeSchema> getAdjacentEdgeSchema(String vertexType, String version) throws SchemaProviderException {
RelationshipSchema relSchema = OxmEdgeRulesLoader.getSchemaForVersion(version);
- Set<EdgeSchema> edges = new HashSet<EdgeSchema>();
+ Set<EdgeSchema> edges = new HashSet<>();
List<EdgeRule> rules = relSchema.lookupAdjacentEdges(vertexType);
-
+
for (EdgeRule rule : rules) {
FromOxmEdgeSchema es = new FromOxmEdgeSchema();
es.fromEdgeRule(rule);
edges.add(es);
}
-
+
return edges;
}
-
+
@Override
public Set<EdgeSchema> getEdgeSchemaForSourceTarget(String sourceType, String targetType, String version) throws SchemaProviderException {
RelationshipSchema relSchema = OxmEdgeRulesLoader.getSchemaForVersion(version);
- Set<EdgeSchema> edges = new HashSet<EdgeSchema>();
+ Set<EdgeSchema> edges = new HashSet<>();
Set<String> relTypes = relSchema.getValidRelationTypes(sourceType, targetType);
-
+
for (String type : relTypes) {
EdgeSchema edgeSchema = getEdgeSchema(type, sourceType, targetType, version);
if (edgeSchema != null) {
edges.add(edgeSchema);
}
}
-
+
return edges;
}
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
package org.onap.aai.nodes;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.transform.*;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.aai.config.NodesConfiguration;
-import org.onap.aai.restclient.MockProvider;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.testutils.TestUtilConfigTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.w3c.dom.Document;
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
@RunWith(SpringRunner.class)
@TestPropertySource(
properties = {
@Autowired
NodeIngestor nodeIngestor;
- public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
+ public static void printDocument(Document doc, OutputStream out) throws TransformerException {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
- transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8")));
+ transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, UTF_8)));
}
@Test
DynamicEntity foo10 = ctx10.newDynamicEntity("Foo");
foo10.set("fooId", "bar");
- assertTrue("bar".equals(foo10.get("fooId")));
+ assertEquals("bar", foo10.get("fooId"));
// should work bc Bar is valid in test_business_v10 schema
DynamicEntity bar10 = ctx10.newDynamicEntity("Bar");
bar10.set("barId", "bar2");
- assertTrue("bar2".equals(bar10.get("barId")));
+ assertEquals("bar2", bar10.get("barId"));
XSDOutputResolver outputResolver10 = new XSDOutputResolver();
ctx10.generateSchema(outputResolver10);
// should work bc Foo.quantity is valid in test_network_v11 schema
DynamicEntity foo11 = ctx11.newDynamicEntity("Foo");
foo11.set("quantity", "12");
- assertTrue("12".equals(foo11.get("quantity")));
+ assertEquals("12", foo11.get("quantity"));
DynamicEntity quux11 = ctx11.newDynamicEntity("Quux");
quux11.set("qManagerName", "some guy");
- assertTrue("some guy".equals(quux11.get("qManagerName")));
+ assertEquals("some guy", quux11.get("qManagerName"));
XSDOutputResolver outputResolver11 = new XSDOutputResolver();
ctx11.generateSchema(outputResolver11);
@Test
public void testGetVersionFromClassName() {
assertEquals(nodeIngestor.getVersionFromClassName("inventory.aai.onap.org.v13.Evc"), new SchemaVersion("v13"));
-
}
@Test
public void testGetVersionFromClassNameNull() {
assertEquals(nodeIngestor.getVersionFromClassName("blah"), new SchemaVersion("v15"));
-
}
@Test
public void testGetObjectsInVersion() {
assertEquals(nodeIngestor.getObjectsInVersion(new SchemaVersion("v13")).size(), 148);
-
}
@Test
assertThat("OXM:\n" + expected, expected, is(content));
}
- private class XSDOutputResolver extends SchemaOutputResolver {
+ private static class XSDOutputResolver extends SchemaOutputResolver {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
package org.onap.aai.nodes;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.transform.*;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.junit.Rule;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.w3c.dom.Document;
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(
properties = {
DynamicEntity foo10 = ctx10.newDynamicEntity("Foo");
foo10.set("fooId", "bar");
- assertTrue("bar".equals(foo10.get("fooId")));
+ assertEquals("bar", foo10.get("fooId"));
// should work bc Bar is valid in test_business_v10 schema
DynamicEntity bar10 = ctx10.newDynamicEntity("Bar");
bar10.set("barId", "bar2");
- assertTrue("bar2".equals(bar10.get("barId")));
+ assertEquals("bar2", bar10.get("barId"));
XSDOutputResolver outputResolver10 = new XSDOutputResolver();
ctx10.generateSchema(outputResolver10);
// should work bc Foo.quantity is valid in test_network_v11 schema
DynamicEntity foo11 = ctx11.newDynamicEntity("Foo");
foo11.set("quantity", "12");
- assertTrue("12".equals(foo11.get("quantity")));
+ assertEquals("12", foo11.get("quantity"));
DynamicEntity quux11 = ctx11.newDynamicEntity("Quux");
quux11.set("qManagerName", "some guy");
- assertTrue("some guy".equals(quux11.get("qManagerName")));
+ assertEquals("some guy", quux11.get("qManagerName"));
XSDOutputResolver outputResolver11 = new XSDOutputResolver();
ctx11.generateSchema(outputResolver11);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
- transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8")));
+ transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, UTF_8)));
}
- private class XSDOutputResolver extends SchemaOutputResolver {
+ private static class XSDOutputResolver extends SchemaOutputResolver {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
-
- // create new file
- // create stream result
File temp = File.createTempFile("schema", ".xsd");
StreamResult result = new StreamResult(temp);
System.out.println("Schema file: " + temp.getAbsolutePath());
- // set system id
result.setSystemId(temp.toURI().toURL().toString());
- // return result
return result;
}
}