@Test public void testMutatePath() throws Exception { String expectedPath; String resultPath; resultPath = rootSearchMutator.mutatePath("v1.0", ResourceNames.ATTENDANCES, "studentId=some_id"); expectedPath = "/" + ResourceNames.STUDENTS + "/" + "some_id" + "/" + ResourceNames.ATTENDANCES; Assert.assertEquals("Invalid mutation:", expectedPath, resultPath); resultPath = rootSearchMutator.mutatePath("v1.0", ResourceNames.ATTENDANCES, "studentId=some_id&something=else"); expectedPath = "/" + ResourceNames.STUDENTS + "/" + "some_id" + "/" + ResourceNames.ATTENDANCES; Assert.assertEquals("Invalid mutation:", expectedPath, resultPath); resultPath = rootSearchMutator.mutatePath("v1.0", ResourceNames.ATTENDANCES, "key1=val1&studentId=some_id&key2=val2"); expectedPath = "/" + ResourceNames.STUDENTS + "/" + "some_id" + "/" + ResourceNames.ATTENDANCES; Assert.assertEquals("Invalid mutation:", expectedPath, resultPath); resultPath = rootSearchMutator.mutatePath("v1.0", ResourceNames.REPORT_CARDS, "schoolId=school_id&studentId=id1,id2,id3&key2=val2"); expectedPath = "/" + ResourceNames.STUDENTS + "/" + "id1,id2,id3" + "/" + ResourceNames.REPORT_CARDS; Assert.assertEquals("Invalid mutation:", expectedPath, resultPath); resultPath = rootSearchMutator.mutatePath("v1.0", ResourceNames.TEACHER_SECTION_ASSOCIATIONS, "schoolId=school_id"); expectedPath = null; Assert.assertEquals("Invalid mutation:", expectedPath, resultPath); }
public String mutatePath(String version, String resource, String queryParameters) { String mutatedPath = null; Map<String, String> parameters = MutatorUtil.getParameterMap(queryParameters); for (Pair<String, String> parameterResourcePair : PARAMETER_RESOURCE_PAIRS) { String curParameter = parameterResourcePair.getLeft(); String curResource = parameterResourcePair.getRight(); if (parameters.containsKey(curParameter)) { if (isValidPath(version, curResource, resource)) { mutatedPath = "/" + curResource + "/" + parameters.get(curParameter) + "/" + resource; break; } } } return mutatedPath; }
RootSearchMutator { public String mutatePath(String version, String resource, String queryParameters) { String mutatedPath = null; Map<String, String> parameters = MutatorUtil.getParameterMap(queryParameters); for (Pair<String, String> parameterResourcePair : PARAMETER_RESOURCE_PAIRS) { String curParameter = parameterResourcePair.getLeft(); String curResource = parameterResourcePair.getRight(); if (parameters.containsKey(curParameter)) { if (isValidPath(version, curResource, resource)) { mutatedPath = "/" + curResource + "/" + parameters.get(curParameter) + "/" + resource; break; } } } return mutatedPath; } }
RootSearchMutator { public String mutatePath(String version, String resource, String queryParameters) { String mutatedPath = null; Map<String, String> parameters = MutatorUtil.getParameterMap(queryParameters); for (Pair<String, String> parameterResourcePair : PARAMETER_RESOURCE_PAIRS) { String curParameter = parameterResourcePair.getLeft(); String curResource = parameterResourcePair.getRight(); if (parameters.containsKey(curParameter)) { if (isValidPath(version, curResource, resource)) { mutatedPath = "/" + curResource + "/" + parameters.get(curParameter) + "/" + resource; break; } } } return mutatedPath; }  }
RootSearchMutator { public String mutatePath(String version, String resource, String queryParameters) { String mutatedPath = null; Map<String, String> parameters = MutatorUtil.getParameterMap(queryParameters); for (Pair<String, String> parameterResourcePair : PARAMETER_RESOURCE_PAIRS) { String curParameter = parameterResourcePair.getLeft(); String curResource = parameterResourcePair.getRight(); if (parameters.containsKey(curParameter)) { if (isValidPath(version, curResource, resource)) { mutatedPath = "/" + curResource + "/" + parameters.get(curParameter) + "/" + resource; break; } } } return mutatedPath; }  String mutatePath(String version, String resource, String queryParameters); }
RootSearchMutator { public String mutatePath(String version, String resource, String queryParameters) { String mutatedPath = null; Map<String, String> parameters = MutatorUtil.getParameterMap(queryParameters); for (Pair<String, String> parameterResourcePair : PARAMETER_RESOURCE_PAIRS) { String curParameter = parameterResourcePair.getLeft(); String curResource = parameterResourcePair.getRight(); if (parameters.containsKey(curParameter)) { if (isValidPath(version, curResource, resource)) { mutatedPath = "/" + curResource + "/" + parameters.get(curParameter) + "/" + resource; break; } } } return mutatedPath; }  String mutatePath(String version, String resource, String queryParameters);  }