package tests; import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.DeltaExtractorJSON; import org.ntlab.deltaExtractor.ExtractedStructure; import org.ntlab.deltaExtractor.IAliasCollector; import org.ntlab.deltaExtractor.IAliasTracker; import org.ntlab.deltaViewer.CollaborationAliasCollector; import org.ntlab.deltaViewer.DeltaAliasCollector; import org.ntlab.trace.Reference; import org.ntlab.trace.ThreadInstance; import org.ntlab.trace.TraceJSON; import org.ntlab.trace.TracePoint; class CollaborationAliasCollectorTest { // Delta Extract Type protected static final String CONTAINER_COMPONENT = "Container-Component"; protected static final String CONTAINER_COMPONENT_COLLECTION = "Container-Component(Collection)"; @Test void testMerge() { Map<String, String[]> argsMap = new HashMap<>(); setArgmentsForDeltaExtract(argsMap); Map<String, List<String>> argsKeysMap = new HashMap<>(); setArgsKeysForPluralDeltaExtract(argsKeysMap, argsMap); // Change Here! // String key = "getterOverlap"; String key = "setterOverlap"; List<String> argsKeys = argsKeysMap.get(key); List<ExtractedStructure> eList = new ArrayList<>(); List<IAliasCollector> dacList = new ArrayList<>(); TraceJSON trace = new TraceJSON(argsMap.get(argsKeys.get(0))[4]); DeltaExtractorJSON s = new DeltaExtractorJSON(trace); for (String argsKey: argsKeys) { if (argsMap.get(argsKey)[5] == CONTAINER_COMPONENT || argsMap.get(argsKey)[5] == CONTAINER_COMPONENT_COLLECTION) { HashMap<String, ThreadInstance> threads = trace.getAllThreads(); if (threads.values().size() == 1) { ThreadInstance thread = threads.values().iterator().next(); // 最後のスレッドを見ているだけ… TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(argsMap.get(argsKey)[0], argsMap.get(argsKey)[1], argsMap.get(argsKey)[2], argsMap.get(argsKey)[3]); IAliasTracker dac = new DeltaAliasCollector(); ExtractedStructure e = s.extract(reference, tp, dac); eList.add(e); dacList.add(dac); } else { for (ThreadInstance thread: threads.values()) { TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(argsMap.get(argsKey)[0], argsMap.get(argsKey)[1], argsMap.get(argsKey)[2], argsMap.get(argsKey)[3]); if (argsMap.get(argsKey)[5] == CONTAINER_COMPONENT_COLLECTION) { reference.setCollection(true); } // reference.setArray(true); // reference.setFinalLocal(true); // reference.setCreation(true); IAliasTracker dac = new DeltaAliasCollector(); ExtractedStructure e = s.extract(reference, tp, dac); System.out.println(e); if (e != null) { eList.add(e); dacList.add(dac); System.out.println("add" + eList.size() + ", " + dacList.size()); } System.out.println("---------------------------"); } } } } CollaborationAliasCollector cac = null; for (IAliasCollector dac: dacList) { if (cac == null ) { cac = new CollaborationAliasCollector(dac); } else { cac.merge(dac); } } for (Alias alias: cac.getAliasList()) { System.out.println(alias.getObjectId() + ", " + alias.getMethodSignature() + " l." + alias.getLineNo() + " : " + alias.getAliasType().toString() + ", (" + alias.getMethodExecution().getEntryTime() + ", " + alias.getMethodExecution().getExitTime() + "), " + alias.getOccurrencePoint().getStatement().getTimeStamp() + ", " + alias.getTimeStamp()); } assertNotNull(cac); for (IAliasCollector dac: dacList) { assertTrue(cac.getAliasList().contains(dac.getAliasList().get(0))); } } private void setArgmentsForDeltaExtract(Map<String, String[]> map){ // Samples of Plural Delta String[] getterOverlap1 = {null, null, "getterOverlap.F","getterOverlap.D", "traces/getterOverlap.txt", CONTAINER_COMPONENT_COLLECTION}; map.put("getterOverlap1", getterOverlap1); String[] getterOverlap2 = {null, null, "getterOverlap.G","getterOverlap.D", "traces/getterOverlap.txt", CONTAINER_COMPONENT_COLLECTION}; map.put("getterOverlap2", getterOverlap2); String[] setterOverlap1 = {null, null, "setterOverlap.F","setterOverlap.C", "traces/setterOverlap.txt", CONTAINER_COMPONENT_COLLECTION}; map.put("setterOverlap1", setterOverlap1); String[] setterOverlap2 = {null, null, "setterOverlap.G","setterOverlap.C", "traces/setterOverlap.txt", CONTAINER_COMPONENT_COLLECTION}; map.put("setterOverlap2", setterOverlap2); } private void setArgsKeysForPluralDeltaExtract(Map<String, List<String>> argsKeysMap, Map<String, String[]> argsMap){ // Samples of Plural Delta argsKeysMap.put("getterOverlap", new ArrayList<String>(Arrays.asList("getterOverlap1", "getterOverlap2"))); argsKeysMap.put("setterOverlap", new ArrayList<String>(Arrays.asList("setterOverlap1", "setterOverlap2"))); } }