+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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.schema;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.onap.crud.exception.CrudException;
+import com.att.aft.dme2.internal.apache.commons.lang.ArrayUtils;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public void shouldContainValidTypes() throws Exception {
Map<String, RelationshipSchema> versionContextMap = new ConcurrentHashMap<>();
loadRelations(versionContextMap);
- assertTrue(versionContextMap.get("v11").isValidType("groupsResourcesIn"));
- assertTrue(versionContextMap.get("v11").isValidType("uses"));
- assertFalse(versionContextMap.get("v11").isValidType("notValidType"));
+ assertTrue(versionContextMap.get("v10").isValidType("groupsResourcesIn"));
+ assertTrue(versionContextMap.get("v10").isValidType("uses"));
+ assertFalse(versionContextMap.get("v10").isValidType("notValidType"));
}
@Test
public void shouldLookUpByRelation() throws Exception {
Map<String, RelationshipSchema> versionContextMap = new ConcurrentHashMap<>();
loadRelations(versionContextMap);
- assertNotNull(versionContextMap.get("v11").lookupRelation("availability-zone:complex:groupsResourcesIn"));
- assertTrue(versionContextMap.get("v11")
- .lookupRelation("availability-zone:complex:groupsResourcesIn").containsKey("usesResource"));
+ assertNotNull(versionContextMap.get("v10").lookupRelation("availability-zone:complex:groupsResourcesIn"));
+ assertTrue(versionContextMap.get("v10")
+ .lookupRelation("availability-zone:complex:groupsResourcesIn").containsKey("prevent-delete"));
}
@Test
public void shouldLookUpByRelationType() throws Exception {
Map<String, RelationshipSchema> versionContextMap = new ConcurrentHashMap<>();
loadRelations(versionContextMap);
- assertNotNull(versionContextMap.get("v11").lookupRelationType("groupsResourcesIn"));
- assertTrue(versionContextMap.get("v11")
- .lookupRelation("availability-zone:complex:groupsResourcesIn").containsKey("usesResource"));
+ assertNotNull(versionContextMap.get("v10").lookupRelationType("groupsResourcesIn"));
+ assertTrue(versionContextMap.get("v10")
+ .lookupRelation("availability-zone:complex:groupsResourcesIn").containsKey("prevent-delete"));
}
private void loadRelations(Map<String, RelationshipSchema> map){
File dir = new File(classLoader.getResource("model").getFile());
File[] allFiles = dir.listFiles((d, name) ->
(propsFilePattern.matcher(name).matches() || rulesFilePattern.matcher(name).matches()));
-
+
+ // Special handling for the v12 file, as it is used for a special test
+ for (File f : allFiles) {
+ if (f.getName().equals("edge_properties_v11.json")) {
+ allFiles = (File[]) ArrayUtils.removeElement(allFiles, f);
+ }
+ }
+
Arrays.stream(allFiles).sorted(Comparator.comparing(File::getName))
.collect(Collectors.groupingBy(f -> myMatcher(versionPattern, f.getName())))
.forEach((e, f) -> map.put(e, jsonFilesLoader(f)));
}
try {
- rsSchema = new RelationshipSchema(fileContents);
+ if (fileContents.size() == 2) {
+ rsSchema = new RelationshipSchema(fileContents);
+ }
} catch (CrudException e) {
e.printStackTrace();
} catch (IOException e) {