-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#23: Base of algorithm for detecting MOVs. Tests.
- Loading branch information
Zdenek Vales
committed
Mar 4, 2020
1 parent
3c2ff60
commit a4ea48d
Showing
3 changed files
with
320 additions
and
14 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...-compatibility-checker/src/main/java/cz/zcu/kiv/crce/apicomp/impl/mov/ApiDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cz.zcu.kiv.crce.apicomp.impl.mov; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ApiDescription extends HashMap<String, Map<String, List<String>>> { | ||
|
||
public void addOperations(String hostname, String pathToEndpoint, List<String> operations) { | ||
if (!containsKey(hostname)) { | ||
put(hostname, new HashMap<>()); | ||
} | ||
|
||
if (!get(hostname).containsKey(pathToEndpoint)) { | ||
get(hostname).put(pathToEndpoint, operations); | ||
} else { | ||
get(hostname).get(pathToEndpoint).addAll(operations); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
255 changes: 255 additions & 0 deletions
255
...-compatibility-checker/src/test/java/cz/zcu/kiv/crce/apicomp/mov/WsdlMovDetectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
package cz.zcu.kiv.crce.apicomp.mov; | ||
|
||
import cz.zcu.kiv.crce.apicomp.impl.mov.ApiDescription; | ||
import cz.zcu.kiv.crce.apicomp.impl.mov.WsdlMovDetector; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class WsdlMovDetectorTest { | ||
|
||
@Test | ||
public void testDetectMov_same() { | ||
ApiDescription api1 = createApi1(), | ||
api2 = createApi1(); | ||
|
||
WsdlMovDetector detector = new WsdlMovDetector(null, null); | ||
boolean[] diffs = detector.detectMov(api1, api2); | ||
|
||
assertFalse("Hosts should be the same!", diffs[0]); | ||
assertFalse("Paths to endpoints should be the same!", diffs[1]); | ||
assertFalse("Operations should be the same!", diffs[2]); | ||
} | ||
|
||
@Test | ||
public void testDetectMov_shuffledOp() { | ||
ApiDescription api1 = createApi1(), | ||
api2 = createApi1_shuffledOperations(); | ||
|
||
WsdlMovDetector detector = new WsdlMovDetector(null, null); | ||
boolean[] diffs = detector.detectMov(api1, api2); | ||
|
||
assertFalse("Hosts should be the same!", diffs[0]); | ||
assertFalse("Paths to endpoints should be the same!", diffs[1]); | ||
assertFalse("Operations should be the same!", diffs[2]); | ||
} | ||
|
||
@Test | ||
public void testDetectMov_differentHost() { | ||
ApiDescription api1 = createApi1(), | ||
api2 = createApi1_diffHost(); | ||
|
||
WsdlMovDetector detector = new WsdlMovDetector(null, null); | ||
boolean[] diffs = detector.detectMov(api1, api2); | ||
|
||
assertTrue("Hosts should not be the same!", diffs[0]); | ||
assertFalse("Paths to endpoints should be the same!", diffs[1]); | ||
assertFalse("Operations should be the same!", diffs[2]); | ||
} | ||
|
||
@Test | ||
public void testDetectMov_differentEndpoints() { | ||
ApiDescription api1 = createApi1(), | ||
api2 = createApi1_diffEndpoint(); | ||
|
||
WsdlMovDetector detector = new WsdlMovDetector(null, null); | ||
boolean[] diffs = detector.detectMov(api1, api2); | ||
|
||
assertFalse("Hosts should be the same!", diffs[0]); | ||
assertTrue("Paths to endpoints should not be the same!", diffs[1]); | ||
assertFalse("Operations should be the same!", diffs[2]); | ||
} | ||
|
||
@Test | ||
public void testDetectMov_differentOperations() { | ||
ApiDescription api1 = createApi1(), | ||
api2 = createApi1_diffOperations(); | ||
|
||
WsdlMovDetector detector = new WsdlMovDetector(null, null); | ||
boolean[] diffs = detector.detectMov(api1, api2); | ||
|
||
assertFalse("Hosts should be the same!", diffs[0]); | ||
assertFalse("Paths to endpoints should be the same!", diffs[1]); | ||
assertTrue("Operations should not be the same!", diffs[2]); | ||
} | ||
|
||
@Test | ||
public void testDetectMov_differentHostAndEndpoints() { | ||
ApiDescription api1 = createApi1(), | ||
api2 = createApi1_diffHostAndEndpoints(); | ||
|
||
WsdlMovDetector detector = new WsdlMovDetector(null, null); | ||
boolean[] diffs = detector.detectMov(api1, api2); | ||
|
||
assertTrue("Hosts should not be the same!", diffs[0]); | ||
assertTrue("Paths to endpoints should not be the same!", diffs[1]); | ||
assertFalse("Operations should be the same!", diffs[2]); | ||
} | ||
|
||
/** | ||
* host -> e1 -> o1-1 | ||
* o1-2 | ||
* o1-3 | ||
* -> e2 -> o2-1 | ||
* o2-2 | ||
* o2-3 | ||
* o2-4 | ||
* | ||
* @return | ||
*/ | ||
private ApiDescription createApi1() { | ||
ApiDescription apiDescription = new ApiDescription(); | ||
|
||
List<String> endpoint1operations = Arrays.asList( | ||
"operation1-1", | ||
"operation1-2", | ||
"operation1-3" | ||
); | ||
|
||
List<String> endpoint2operations = Arrays.asList( | ||
"operation2-1", | ||
"operation2-2", | ||
"operation2-3", | ||
"operation2-4" | ||
); | ||
|
||
apiDescription.addOperations("http://host-1.com", "/path/to/endpoint1", endpoint1operations); | ||
apiDescription.addOperations("http://host-1.com", "/path/to/endpoint2", endpoint2operations); | ||
|
||
return apiDescription; | ||
} | ||
|
||
/** | ||
* Same as API 1 but operation names are shuffled | ||
* @return | ||
*/ | ||
private ApiDescription createApi1_shuffledOperations() { | ||
ApiDescription apiDescription = new ApiDescription(); | ||
|
||
List<String> endpoint1operations = Arrays.asList( | ||
"operation1-3", | ||
"operation1-1", | ||
"operation1-2" | ||
); | ||
|
||
List<String> endpoint2operations = Arrays.asList( | ||
"operation2-3", | ||
"operation2-2", | ||
"operation2-4", | ||
"operation2-1" | ||
); | ||
|
||
apiDescription.addOperations("http://host-1.com", "/path/to/endpoint2", endpoint2operations); | ||
apiDescription.addOperations("http://host-1.com", "/path/to/endpoint1", endpoint1operations); | ||
|
||
return apiDescription; | ||
} | ||
|
||
/** | ||
* Same as API 1 but host is different | ||
* @return | ||
*/ | ||
private ApiDescription createApi1_diffHost() { | ||
ApiDescription apiDescription = new ApiDescription(); | ||
|
||
List<String> endpoint1operations = Arrays.asList( | ||
"operation1-1", | ||
"operation1-2", | ||
"operation1-3" | ||
); | ||
|
||
List<String> endpoint2operations = Arrays.asList( | ||
"operation2-1", | ||
"operation2-2", | ||
"operation2-3", | ||
"operation2-4" | ||
); | ||
|
||
apiDescription.addOperations("http://different-host-1.com", "/path/to/endpoint1", endpoint1operations); | ||
apiDescription.addOperations("http://different-host-1.com", "/path/to/endpoint2", endpoint2operations); | ||
|
||
return apiDescription; | ||
} | ||
|
||
/** | ||
* Same as API 1 but path to endpoints are different | ||
* @return | ||
*/ | ||
private ApiDescription createApi1_diffEndpoint() { | ||
ApiDescription apiDescription = new ApiDescription(); | ||
|
||
List<String> endpoint1operations = Arrays.asList( | ||
"operation1-1", | ||
"operation1-2", | ||
"operation1-3" | ||
); | ||
|
||
List<String> endpoint2operations = Arrays.asList( | ||
"operation2-1", | ||
"operation2-2", | ||
"operation2-3", | ||
"operation2-4" | ||
); | ||
|
||
apiDescription.addOperations("http://host-1.com", "/this/way/to/endpoint1", endpoint1operations); | ||
apiDescription.addOperations("http://host-1.com", "/this/way/to/endpoint2", endpoint2operations); | ||
|
||
return apiDescription; | ||
} | ||
|
||
/** | ||
* Same as API 1 but operation names are different. | ||
* @return | ||
*/ | ||
private ApiDescription createApi1_diffOperations() { | ||
ApiDescription apiDescription = new ApiDescription(); | ||
|
||
List<String> endpoint1operations = Arrays.asList( | ||
"function1-1", | ||
"function1-2", | ||
"function1-3" | ||
); | ||
|
||
List<String> endpoint2operations = Arrays.asList( | ||
"function2-1", | ||
"function2-2", | ||
"function2-3", | ||
"function2-4" | ||
); | ||
|
||
apiDescription.addOperations("http://host-1.com", "/path/to/endpoint1", endpoint1operations); | ||
apiDescription.addOperations("http://host-1.com", "/path/to/endpoint2", endpoint2operations); | ||
|
||
return apiDescription; | ||
} | ||
|
||
/** | ||
* Api 1 but hostname and enpoint names are different | ||
* @return | ||
*/ | ||
private ApiDescription createApi1_diffHostAndEndpoints() { | ||
ApiDescription apiDescription = new ApiDescription(); | ||
|
||
List<String> endpoint1operations = Arrays.asList( | ||
"operation1-1", | ||
"operation1-2", | ||
"operation1-3" | ||
); | ||
|
||
List<String> endpoint2operations = Arrays.asList( | ||
"operation2-1", | ||
"operation2-2", | ||
"operation2-3", | ||
"operation2-4" | ||
); | ||
|
||
apiDescription.addOperations("http://different-host-1.com", "/this/way/to/endpoint1", endpoint1operations); | ||
apiDescription.addOperations("http://different-host-1.com", "/this/way/to/endpoint2", endpoint2operations); | ||
|
||
return apiDescription; | ||
} | ||
} |