SpecFileProcessor { public String toProxiedSpec(final String specFile, final URI repoUri) throws InvalidSpecFileException { try { return transformSpec(specFile, repoUri); } catch (IOException ioe) { throw new InvalidSpecFileException(specFile, ioe); } } @Inject  SpecFileProcessor(final GitApiHelper gitApiHelper); String toProxiedSpec(final String specFile, final URI repoUri); URI extractExternalUri(final String specFile);  }
@Test public void gitHubToProxiedSpecPositiveTest() throws Exception { String spec = "{" + "\"name\": \"MasonryHidden\"," + "\"version\": \"1.0.0\"," + "\"source\": {\n" + "\"git\": \"https: "\"tag\": \"0.5.0\"" + "}" + "}"; String transformedSpec = "{\n" + " \"name\" : \"MasonryHidden\",\n" + " \"version\" : \"1.0.0\",\n" + " \"source\" : {\n" + " \"http\" : \"http: " }\n" + "}"; URI repoUri = URI.create("http: String res = new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); assertThat(res, is(transformedSpec)); }
@Test public void gitHubToProxiedSpecInvalidTagTest() throws Exception { String spec = "{" + "\"name\": \"MasonryHidden\"," + "\"version\": \"1.0.0\"," + "\"source\": {\n" + "\"git\": \"https: "\"tag\": 0.01" + "}" + "}"; String transformedSpec = "{\n" + " \"name\" : \"MasonryHidden\",\n" + " \"version\" : \"1.0.0\",\n" + " \"source\" : {\n" + " \"http\" : \"http: " }\n" + "}"; URI repoUri = URI.create("http: String res = new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); assertThat(res, is(transformedSpec)); }
@Test public void httpToProxiedSpecTest() throws Exception { String spec = "{" + "\"name\": \"AppSpectorTVSDK\"," + "\"version\": \"1.0.0\"," + "\"source\": {\n" + "\"http\": \"https: "}" + "}"; String transformedSpec = "{\n" + " \"name\" : \"AppSpectorTVSDK\",\n" + " \"version\" : \"1.0.0\",\n" + " \"source\" : {\n" + " \"http\" : \"http: " }\n" + "}"; URI repoUri = URI.create("http: String res = new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); assertThat(res, is(transformedSpec)); }
@Test(expected = InvalidSpecFileException.class) public void gitHubToProxiedSpecInvalidGitUriTest() throws Exception { String spec = "{" + "\"name\": \"MasonryHidden\"," + "\"version\": \"1.0.0\"," + "\"source\": {\n" + "\"git\": \"git@gitlab.gbksoft.net:gbksoft-mobile-department/ios/gbkslidemenu.git\"," + "\"tag\": \"0.5.0\"" + "}" + "}"; URI repoUri = URI.create("http: new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); }
@Test(expected = InvalidSpecFileException.class) public void testInvalidJson() throws Exception { new SpecFileProcessor(gitApiHelper).toProxiedSpec("invalid_json", URI.create("http: }
@Test(expected = InvalidSpecFileException.class) public void gitHubToProxiedSpecNoSourceTest() throws Exception { String spec = "{\"name\": \"MasonryHidden\",\"version\": \"1.0.0\"}"; URI repoUri = URI.create("http: new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); }
@Test(expected = InvalidSpecFileException.class) public void gitHubToProxiedSpecNoNameTest() throws Exception { String spec = "{" + "\"version\": \"1.0.0\"," + "\"source\": {\n" + "\"git\": \"git@gitlab.gbksoft.net:gbksoft-mobile-department/ios/gbkslidemenu.git\"," + "\"tag\": \"0.5.0\"" + "}" + "}"; URI repoUri = URI.create("http: new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); }
@Test(expected = InvalidSpecFileException.class) public void gitHubToProxiedSpecNoVersionTest() throws Exception { String spec = "{" + "\"name\": \"MasonryHidden\"," + "\"source\": {\n" + "\"git\": \"git@gitlab.gbksoft.net:gbksoft-mobile-department/ios/gbkslidemenu.git\"," + "\"tag\": \"0.5.0\"" + "}" + "}"; URI repoUri = URI.create("http: new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); }
@Test public void gitHubToProxiedSpecVersionIncludeNonPrintableCharactersTest() throws Exception { String spec = "{\n" + " \"name\": \"Realm\",\n" + " \"version\": \"0.92.3\\n\",\n" + " \"source\": {\n" + " \"git\": \"https: " \"tag\": \"v0.92.3\"\n" + " }\n" + "}"; URI repoUri = URI.create("http: String res = new SpecFileProcessor(gitApiHelper).toProxiedSpec(spec, repoUri); assertThat(res.contains("/Realm/0.92.3/"), is(true)); }