Here are the examples of the java api class java.net.URI taken from open source projects.
1. UrlHelperTest#testCollectionInDomainUrl()
View license@Test public void testCollectionInDomainUrl() { //vsts account final URI accountUri = URI.create("https://myaccount.visualstudio.com"); //collection not in domain final URI defaultCollectionUri = UrlHelper.getCollectionURI(accountUri, "DefaultCollection"); assertEquals(URI.create("https://myaccount.visualstudio.com/DefaultCollection"), defaultCollectionUri); //collection in domain final URI inDomainCollectionUri = UrlHelper.getCollectionURI(accountUri, "myaccount"); assertEquals(accountUri, inDomainCollectionUri); //onprem server final URI serverUri = URI.create("http://myserver:8080/tfs"); final URI collectionUri1 = UrlHelper.getCollectionURI(serverUri, "FabrikamCollection"); assertEquals(URI.create("http://myserver:8080/tfs/FabrikamCollection"), collectionUri1); final URI collectionUri2 = UrlHelper.getCollectionURI(serverUri, "myserver"); assertEquals(URI.create("http://myserver:8080/tfs/myserver"), collectionUri2); }
2. URIUtilsTest#testResolve()
View license/** * @throws Exception */ @Test public void testResolve() throws Exception { URI baseWithTrailingSlash = new URI("http://www.rssowl.org/"); URI baseWithoutTrailingSlash = new URI("http://www.rssowl.org"); URI base2WithTrailingSlash = new URI("http://www.rssowl.org/other/"); URI base2WithoutTrailingSlash = new URI("http://www.rssowl.org/other"); URI relativeWithLeadingSlash = new URI("/path/download.mp3"); URI relativeWithoutLeadingSlash = new URI("path/download.mp3"); assertEquals("http://www.rssowl.org/path/download.mp3", URIUtils.resolve(baseWithTrailingSlash, relativeWithLeadingSlash).toString()); assertEquals("http://www.rssowl.org/path/download.mp3", URIUtils.resolve(baseWithTrailingSlash, relativeWithoutLeadingSlash).toString()); assertEquals("http://www.rssowl.org/path/download.mp3", URIUtils.resolve(baseWithoutTrailingSlash, relativeWithLeadingSlash).toString()); assertEquals("http://www.rssowl.org/path/download.mp3", URIUtils.resolve(baseWithoutTrailingSlash, relativeWithoutLeadingSlash).toString()); assertEquals("http://www.rssowl.org/path/download.mp3", URIUtils.resolve(base2WithTrailingSlash, relativeWithLeadingSlash).toString()); assertEquals("http://www.rssowl.org/other/path/download.mp3", URIUtils.resolve(base2WithTrailingSlash, relativeWithoutLeadingSlash).toString()); assertEquals("http://www.rssowl.org/path/download.mp3", URIUtils.resolve(base2WithoutTrailingSlash, relativeWithLeadingSlash).toString()); assertEquals("http://www.rssowl.org/other/path/download.mp3", URIUtils.resolve(base2WithoutTrailingSlash, relativeWithoutLeadingSlash).toString()); }
3. CompilerErrorsTest#testValidationMatchingNavigation()
View license@Test public void testValidationMatchingNavigation() throws Exception { URI resource = getClass().getResource("/corrupted/matching-navigation/parent_flow.sl").toURI(); URI subFlow = getClass().getResource("/corrupted/matching-navigation/child_flow.sl").toURI(); URI operation1 = getClass().getResource("/corrupted/matching-navigation/test_op.sl").toURI(); URI operation2 = getClass().getResource("/corrupted/matching-navigation/check_weather.sl").toURI(); URI operation3 = getClass().getResource("/corrupted/matching-navigation/get_time_zone.sl").toURI(); URI operation4 = getClass().getResource("/corrupted/matching-navigation/check_number.sl").toURI(); Set<SlangSource> dependencies = new HashSet<>(); dependencies.add(SlangSource.fromFile(subFlow)); dependencies.add(SlangSource.fromFile(operation1)); dependencies.add(SlangSource.fromFile(operation2)); dependencies.add(SlangSource.fromFile(operation3)); dependencies.add(SlangSource.fromFile(operation4)); exception.expect(IllegalArgumentException.class); exception.expectMessage("Cannot compile flow: 'child_flow' since for step: 'step01', the result 'NEGATIVE' " + "of its dependency: 'user.ops.get_time_zone' has no matching navigation"); compiler.compile(SlangSource.fromFile(resource), dependencies); }
4. SubFlowSystemTest#testCompileAndRunSubFlowBasic()
View license@Test public void testCompileAndRunSubFlowBasic() throws Exception { URI resource = getClass().getResource("/yaml/sub-flow/parent_flow.sl").toURI(); URI subFlow = getClass().getResource("/yaml/sub-flow/child_flow.sl").toURI(); URI operation1 = getClass().getResource("/yaml/test_op.sl").toURI(); URI operation2 = getClass().getResource("/yaml/check_weather.sl").toURI(); URI operation3 = getClass().getResource("/yaml/get_time_zone.sl").toURI(); URI operation4 = getClass().getResource("/yaml/check_number.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(subFlow), SlangSource.fromFile(operation1), SlangSource.fromFile(operation2), SlangSource.fromFile(operation3), SlangSource.fromFile(operation4)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Assert.assertEquals("the system properties size is not as expected", 2, compilationArtifact.getSystemProperties().size()); Set<SystemProperty> systemProperties = new HashSet<>(); systemProperties.add(new SystemProperty("user.sys", "props.port", "22")); systemProperties.add(new SystemProperty("user.sys", "props.alla", "balla")); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("input1", ValueFactory.create("value1")); ScoreEvent event = trigger(compilationArtifact, userInputs, systemProperties); Assert.assertEquals(ScoreLangConstants.EVENT_EXECUTION_FINISHED, event.getEventType()); }
5. ClientDataSource#main()
View licensepublic static void main(String[] args) throws URISyntaxException { URI uri1; uri1 = new URI("datasource", null, "/path", null, null); uri1 = new URI("datasource", null, "/path", null, null); System.out.println("uri = " + uri1); uri1 = new URI("datasource", "host", "/path", null, null); System.out.println("uri = " + uri1); uri1 = new URI("datasource", "host", "/path", "query", "fragment"); System.out.println("uri = " + uri1); uri1 = new URI("jdbc:derby://localhost:8080/databaseName"); print(uri1); print(new URI(uri1.getSchemeSpecificPart())); }
6. FactorImports#outputFileFor()
View licenseprivate static File outputFileFor(File file, File baseDir, File outdir) { URI base = baseDir.getAbsoluteFile().toURI(); URI abs = file.getAbsoluteFile().toURI(); URI rel = base.relativize(abs); if (rel.isAbsolute()) { System.out.println("Cannot relativize " + file); return null; } URI outbase = outdir.toURI(); URI out = CodeGenUtil.resolve(outbase, rel); return new File(out); }
7. FilesDatasetSourceTest#setUp()
View license@Before public void setUp() throws Exception { m_configNoSelfURI = new URI("input/data/dataset/test1/source.json"); m_configSelfURI = new URI("input/data/dataset/test1/source_self.json"); m_inputDir = new URI("input/data/dataset/test1/input_data"); m_inputSelfDir = new URI("input/data/dataset/test1/input_data_self"); m_outputDir = new URI("output/data/dataset/test1"); m_inputFileSrc = FileSources.getFileSource(m_inputDir); m_inputSelfFileSrc = FileSources.getFileSource(m_inputSelfDir); m_outputFileSrc = FileSources.getFileSource(m_outputDir); m_configNoSelf = FilesDatasetSourceConfig.load(new ConfigDescriptor(m_configNoSelfURI)); m_configSelf = FilesDatasetSourceConfig.load(new ConfigDescriptor(m_configSelfURI)); m_inputSrc = new FilesDatasetSource(m_configNoSelf, m_inputFileSrc); m_outputSrc = new FilesDatasetSource(m_configNoSelf, m_outputFileSrc); }
8. URISupportTest#testCompositeCreateURIWithQuery()
View license@Test public void testCompositeCreateURIWithQuery() throws Exception { String queryString = "query=value"; URI originalURI = new URI("outerscheme:(innerscheme:innerssp)"); URI querylessURI = originalURI; assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI)); assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, "")); assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString)); originalURI = new URI("outerscheme:(innerscheme:innerssp)?outerquery=0"); assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI)); assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, "")); assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString)); originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)"); querylessURI = originalURI; assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI)); assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, "")); assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString)); originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)?outerquery=0"); assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI)); assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, "")); assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString)); }
9. FactorImports#relativeURIFor()
View licenseprivate static String relativeURIFor(File source, File target) { URI base = source.getAbsoluteFile().toURI(); URI abs = target.getAbsoluteFile().toURI(); // find common substring... URI commonBase = commonAncestor(base, abs); if (commonBase == null) return abs.toString(); URI baserel = commonBase.relativize(base); URI targetrel = commonBase.relativize(abs); if (baserel.isAbsolute() || targetrel.isAbsolute()) return abs.toString(); String prefix = ""; String sourceRel = baserel.toString(); for (int i = 0; i < sourceRel.length(); ) { i = sourceRel.indexOf('/', i); if (i < 0) break; prefix += "../"; i += 1; } return prefix + targetrel.toString(); }
10. XmlParser#getCumulativeXmlBase()
View license/** * Computes a cumulative value of {@code xml:base} based on a prior value * and a new value. If the new value is an absolute URI, it is returned * unchanged. If the new value is a relative URI, it is combined with the * prior value. * * @param curBase * Current value of {@code xml:base} or {@code null}. * * @param newBase * New value of {@code xml:base}. * * @return Combined value of {@code xml:base}, which is guaranteed to be * an absolute URI. * * @throws URISyntaxException * Invalid value of {@code xml:base} (doesn't parse as a valid * relative/absolute URI depending on {@code xml:base} context). */ static String getCumulativeXmlBase(String curBase, String newBase) throws URISyntaxException { URI newBaseUri = new URI(newBase); if (curBase == null || curBase.equals("")) { // We require an absolute URI. if (!newBaseUri.isAbsolute()) { throw new URISyntaxException(newBase, "No xml:base established--need an absolute URI."); } return newBase; } URI curBaseUri = new URI(curBase); URI resultUri = curBaseUri.resolve(newBaseUri); assert resultUri.isAbsolute(); return resultUri.toString(); }
11. XmlParser#getCumulativeXmlBase()
View license/** * Computes a cumulative value of {@code xml:base} based on a prior value * and a new value. If the new value is an absolute URI, it is returned * unchanged. If the new value is a relative URI, it is combined with the * prior value. * * @param curBase * Current value of {@code xml:base} or {@code null}. * * @param newBase * New value of {@code xml:base}. * * @return Combined value of {@code xml:base}, which is guaranteed to be * an absolute URI. * * @throws URISyntaxException * Invalid value of {@code xml:base} (doesn't parse as a valid * relative/absolute URI depending on {@code xml:base} context). */ static String getCumulativeXmlBase(String curBase, String newBase) throws URISyntaxException { URI newBaseUri = new URI(newBase); if (curBase == null || curBase.equals("")) { // We require an absolute URI. if (!newBaseUri.isAbsolute()) { throw new URISyntaxException(newBase, "No xml:base established--need an absolute URI."); } return newBase; } URI curBaseUri = new URI(curBase); URI resultUri = curBaseUri.resolve(newBaseUri); assert resultUri.isAbsolute(); return resultUri.toString(); }
12. TestConfigClientUtils#testGetConfigKeyPath()
View license@Test public void testGetConfigKeyPath() throws URISyntaxException { String expected = "/datasets/a1/a2"; URI clientAbsURI = new URI("etl-hdfs://eat1-nertznn01.grid.linkedin.com:9000/user/mitu/HdfsBasedConfigTest/datasets/a1/a2"); ConfigKeyPath result = ConfigClientUtils.buildConfigKeyPath(clientAbsURI, mockConfigStore); Assert.assertEquals(result.toString(), expected); URI clientRelativeURI = new URI("etl-hdfs:///datasets/a1/a2"); result = ConfigClientUtils.buildConfigKeyPath(clientRelativeURI, mockConfigStore); Assert.assertEquals(result.toString(), expected); clientRelativeURI = new URI("etl-hdfs:/datasets/a1/a2"); result = ConfigClientUtils.buildConfigKeyPath(clientRelativeURI, mockConfigStore); Assert.assertEquals(result.toString(), expected); ConfigKeyPath configKey = SingleLinkedListConfigKeyPath.ROOT.createChild("data").createChild("databases").createChild("Identity"); // client app pass URI without authority URI adjusted = ConfigClientUtils.buildUriInClientFormat(configKey, mockConfigStore, false); Assert.assertTrue(adjusted.toString().equals("etl-hdfs:/data/databases/Identity")); // client app pass URI with authority adjusted = ConfigClientUtils.buildUriInClientFormat(configKey, mockConfigStore, true); Assert.assertTrue(adjusted.toString().equals("etl-hdfs://eat1-nertznn01.grid.linkedin.com:9000/user/mitu/HdfsBasedConfigTest/data/databases/Identity")); }
13. CompilerHelperTest#testCompileMixedSlangFiles()
View license@Test public void testCompileMixedSlangFiles() throws Exception { URI flowFilePath = getClass().getResource("/flow.sl").toURI(); URI folderPath = getClass().getResource("/mixed_sl_files/").toURI(); URI dependency1 = getClass().getResource("/mixed_sl_files/configuration/properties/executables/test_flow.sl").toURI(); URI dependency2 = getClass().getResource("/mixed_sl_files/configuration/properties/executables/test_op.sl").toURI(); compilerHelper.compile(flowFilePath.getPath(), Lists.newArrayList(folderPath.getPath())); Mockito.verify(slang).compile(SlangSource.fromFile(flowFilePath), Sets.newHashSet(SlangSource.fromFile(dependency1), SlangSource.fromFile(dependency2))); }
14. CompileDependenciesTest#filesThatAreNotImportedShouldNotBeCompiled()
View license@Test public void filesThatAreNotImportedShouldNotBeCompiled() throws Exception { URI flow = getClass().getResource("/basic_flow.yaml").toURI(); URI notImportedOperation = getClass().getResource("/flow_with_data.yaml").toURI(); URI importedOperation = getClass().getResource("/test_op.sl").toURI(); URI importedOperation2 = getClass().getResource("/check_Weather.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(notImportedOperation)); path.add(SlangSource.fromFile(importedOperation)); path.add(SlangSource.fromFile(importedOperation2)); CompilationArtifact compilationArtifact = compiler.compile(SlangSource.fromFile(flow), path); Assert.assertThat(compilationArtifact.getDependencies(), Matchers.<String, ExecutionPlan>hasKey("user.ops.test_op")); Assert.assertThat(compilationArtifact.getDependencies(), not(Matchers.<String, ExecutionPlan>hasKey("slang.sample.flows.SimpleFlow"))); }
15. CompileFlowWithMultipleStepsTest#testCompileFlowBasic()
View license@Test public void testCompileFlowBasic() throws Exception { URI flow = getClass().getResource("/flow_with_multiple_steps.yaml").toURI(); URI operation1 = getClass().getResource("/test_op.sl").toURI(); URI operation2 = getClass().getResource("/java_op.sl").toURI(); URI operation3 = getClass().getResource("/check_Weather.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operation1)); path.add(SlangSource.fromFile(operation2)); path.add(SlangSource.fromFile(operation3)); CompilationArtifact compilationArtifact = compiler.compile(SlangSource.fromFile(flow), path); ExecutionPlan executionPlan = compilationArtifact.getExecutionPlan(); Assert.assertNotNull("execution plan is null", executionPlan); Assert.assertEquals("there is a different number of steps than expected", 10, executionPlan.getSteps().size()); Assert.assertEquals("execution plan name is different than expected", "flow_with_multiple_steps", executionPlan.getName()); Assert.assertEquals("the dependencies size is not as expected", 3, compilationArtifact.getDependencies().size()); }
16. CompilerErrorsTest#testFlowWithMissingSpaceBeforeFirstImport()
View license@Test public void testFlowWithMissingSpaceBeforeFirstImport() throws Exception { //covers "mapping values are not allowed here" error URI resource = getClass().getResource("/corrupted/flow_with_missing_space_before_first_import.sl").toURI(); URI operations = getClass().getResource("/java_op.sl").toURI(); URI checkWeather = getClass().getResource("/check_Weather.sl").toURI(); URI flows = getClass().getResource("/flow_with_data.yaml").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operations)); path.add(SlangSource.fromFile(flows)); path.add(SlangSource.fromFile(checkWeather)); exception.expect(RuntimeException.class); exception.expectMessage(ParserExceptionHandler.MAPPING_VALUES_NOT_ALLOWED_HERE_ERROR); exception.expectMessage(ParserExceptionHandler.KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG); compiler.compile(SlangSource.fromFile(resource), path); }
17. CompilerErrorsTest#testFlowWithWrongIndentation()
View license@Test public void testFlowWithWrongIndentation() throws Exception { //covers "Unable to find property 'X' on class: io.cloudslang.lang.compiler.parser.model.ParsedSlang" URI resource = getClass().getResource("/corrupted/flow_with_wrong_indentation.sl").toURI(); URI operations = getClass().getResource("/java_op.sl").toURI(); URI flows = getClass().getResource("/flow_with_data.yaml").toURI(); URI checkWeather = getClass().getResource("/check_Weather.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operations)); path.add(SlangSource.fromFile(flows)); path.add(SlangSource.fromFile(checkWeather)); exception.expect(RuntimeException.class); exception.expectMessage(ParserExceptionHandler.CANNOT_CREATE_PROPERTY_ERROR); exception.expectMessage("Unable to find property"); exception.expectMessage("is not supported by CloudSlang"); compiler.compile(SlangSource.fromFile(resource), path); }
18. CompilerErrorsTest#testFlowWhereMapCannotBeCreated()
View license@Test public void testFlowWhereMapCannotBeCreated() throws Exception { //covers "No single argument constructor found for interface java.util.Map" URI resource = getClass().getResource("/corrupted/flow_where_map_cannot_be_created.sl").toURI(); URI operations = getClass().getResource("/java_op.sl").toURI(); URI flows = getClass().getResource("/flow_with_data.yaml").toURI(); URI checkWeather = getClass().getResource("/check_Weather.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operations)); path.add(SlangSource.fromFile(flows)); path.add(SlangSource.fromFile(checkWeather)); exception.expect(RuntimeException.class); exception.expectMessage(ParserExceptionHandler.CANNOT_CREATE_PROPERTY_ERROR); exception.expectMessage(ParserExceptionHandler.KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG); compiler.compile(SlangSource.fromFile(resource), path); }
19. CompilerErrorsTest#testValidationOfFlowThatCallsCorruptedFlow()
View license@Test public void testValidationOfFlowThatCallsCorruptedFlow() throws Exception { URI flowUri = getClass().getResource("/corrupted/flow_that_calls_corrupted_flow.sl").toURI(); URI operation1Uri = getClass().getResource("/test_op.sl").toURI(); URI operation2Uri = getClass().getResource("/check_op.sl").toURI(); URI operation3Uri = getClass().getResource("/corrupted/flow_input_in_step_same_name_as_dependency_output.sl").toURI(); Set<SlangSource> dependencies = new HashSet<>(); dependencies.add(SlangSource.fromFile(operation1Uri)); dependencies.add(SlangSource.fromFile(operation2Uri)); dependencies.add(SlangSource.fromFile(operation3Uri)); exception.expect(IllegalArgumentException.class); exception.expectMessage("Cannot compile flow 'io.cloudslang.flow_input_in_step_same_name_as_dependency_output'. " + "Step 'explicit_alias' has input 'balla' with the same name as the one of the outputs of 'user.ops.test_op'."); compiler.compile(SlangSource.fromFile(flowUri), dependencies); }
20. NavigationTest#testDefaultSuccessNavigation()
View license@Test public void testDefaultSuccessNavigation() throws Exception { URI resource = getClass().getResource("/yaml/flow_default_navigation.yaml").toURI(); URI operationPython = getClass().getResource("/yaml/produce_default_navigation.sl").toURI(); URI operation2Python = getClass().getResource("/yaml/send_email_mock.sl").toURI(); URI operation3Python = getClass().getResource("/yaml/check_weather.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operationPython), SlangSource.fromFile(operation2Python), SlangSource.fromFile(operation3Python)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("navigationType", ValueFactory.create("success")); userInputs.put("emailHost", ValueFactory.create("emailHost")); userInputs.put("emailPort", ValueFactory.create("25")); userInputs.put("emailSender", ValueFactory.create("[email protected]")); userInputs.put("emailRecipient", ValueFactory.create("[email protected]")); Map<String, StepData> steps = triggerWithData(compilationArtifact, userInputs, new HashSet<SystemProperty>()).getSteps(); Assert.assertEquals("produce_default_navigation", steps.get(FIRST_STEP_PATH).getName()); Assert.assertEquals("check_weather", steps.get(SECOND_STEP_KEY).getName()); }
21. NavigationTest#testDefaultOnFailureNavigation()
View license@Test public void testDefaultOnFailureNavigation() throws Exception { URI resource = getClass().getResource("/yaml/flow_default_navigation.yaml").toURI(); URI operationPython = getClass().getResource("/yaml/produce_default_navigation.sl").toURI(); URI operation2Python = getClass().getResource("/yaml/send_email_mock.sl").toURI(); URI operation3Python = getClass().getResource("/yaml/check_weather.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operationPython), SlangSource.fromFile(operation2Python), SlangSource.fromFile(operation3Python)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("navigationType", ValueFactory.create("failure")); userInputs.put("emailHost", ValueFactory.create("emailHost")); userInputs.put("emailPort", ValueFactory.create("25")); userInputs.put("emailSender", ValueFactory.create("[email protected]")); userInputs.put("emailRecipient", ValueFactory.create("[email protected]")); Map<String, StepData> steps = triggerWithData(compilationArtifact, userInputs, new HashSet<SystemProperty>()).getSteps(); Assert.assertEquals("produce_default_navigation", steps.get(FIRST_STEP_PATH).getName()); Assert.assertEquals("send_error_mail", steps.get(SECOND_STEP_KEY).getName()); }
22. NavigationTest#testOnFailureNavigationMoreSteps()
View license@Test public void testOnFailureNavigationMoreSteps() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage("Below 'on_failure' property there should be only one step"); URI resource = getClass().getResource("/yaml/on_failure_more_steps.sl").toURI(); URI operationPython = getClass().getResource("/yaml/produce_default_navigation.sl").toURI(); URI operation2Python = getClass().getResource("/yaml/send_email_mock.sl").toURI(); URI operation3Python = getClass().getResource("/yaml/check_weather.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operationPython), SlangSource.fromFile(operation2Python), SlangSource.fromFile(operation3Python)); slang.compile(SlangSource.fromFile(resource), path); }
23. XBayaConfiguration#loadConfiguration()
View licenseprivate void loadConfiguration(URI uri) { LeadDeploymentConfig config = LeadDeploymentConfig.loadConfig(null, uri); URI gpel = config.getGpelUrl(); if (gpel != null) { this.gpelEngineURL = config.getGpelUrl(); } URI dsc = config.getDscUrl(); if (dsc != null) { this.dscURL = dsc; } URI broker = config.getBrokerUrl(); if (broker != null) { this.brokerURL = broker; } URI msgBox = config.getMsgBoxUrl(); if (msgBox != null) { this.messageBoxURL = msgBox; } }
24. StagedDatasetSourceTest#setUp()
View license@Before public void setUp() throws Exception { m_configURI = new URI("input/data/dataset/test1/source.json"); m_inputDir = new URI("input/data/dataset/test1/input_data"); m_actualDir = new URI("output/data/sources/staged/actual"); m_stageDir = new URI("output/data/sources/staged/stage"); m_inputFileSrc = FileSources.getFileSource(m_inputDir); m_actualFileSrc = FileSources.getFileSource(m_actualDir); m_stageFileSrc = FileSources.getFileSource(m_stageDir); m_config = FilesDatasetSourceConfig.load(new ConfigDescriptor(m_configURI)); m_inputSrc = new FilesDatasetSource(m_config, m_inputFileSrc); m_actualSrc = new FilesDatasetSource(m_config, m_actualFileSrc); m_stageSrc = new FilesDatasetSource(m_config, m_stageFileSrc); m_outputSrc = new StagedDatasetSource(m_actualSrc, m_stageSrc); m_actualFileSrc.ensureExists(); m_actualFileSrc.clear(); m_stageFileSrc.ensureExists(); m_stageFileSrc.clear(); }
25. CxfCacheUriInfoIssueTest#checkContextForDifferentHostNamesRequests()
View license@Test public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException, URISyntaxException { URI uri1 = URI.create(getEndpoint().toString() + "$metadata"); HttpGet get1 = new HttpGet(uri1); HttpResponse response1 = getHttpClient().execute(get1); assertNotNull(response1); URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot(); assertEquals(uri1.getHost(), serviceRoot1.getHost()); get1.reset(); URI uri2 = new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(), uri1.getFragment()); HttpGet get2 = new HttpGet(uri2); HttpResponse response2 = getHttpClient().execute(get2); assertNotNull(response2); URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot(); assertEquals(uri2.getHost(), serviceRoot2.getHost()); }
26. ApplicationConfigurationTest#testURLFormats()
View license@Test public void testURLFormats() throws MalformedURLException, URISyntaxException { URI file = new URI("file:/tmp/"); String path = file.getSchemeSpecificPart(); Assert.assertEquals("/tmp/", path); URI fileInJar = new URI("jar:file:/tmp/my.jar!/"); String path1 = fileInJar.getSchemeSpecificPart(); Assert.assertEquals("file:/tmp/my.jar!/", path1); URI fileInZip = new URI("zip:D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!"); String path2 = fileInZip.getSchemeSpecificPart(); Assert.assertEquals("D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!", path2); URI fileInVfszip = new URI("vfsfile:/tmp/SOA%20Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml"); String path3 = fileInVfszip.getSchemeSpecificPart(); Assert.assertEquals("/tmp/SOA Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml", path3); }
27. TestHttpUtils#testResolveUri()
View licensepublic void testResolveUri() throws URISyntaxException { URI baseUri = new URI("http://localhost/base/directory/"); // Test absolute resolve. URI resolvedAbsoluteUri = HttpUtils.resolveUri(baseUri, "/path/to/file"); assertEquals("http://localhost/path/to/file", resolvedAbsoluteUri.toString()); // Test relative resolve. URI resolvedRelativeUri = HttpUtils.resolveUri(baseUri, "path/to/file"); assertEquals("http://localhost/base/directory/path/to/file", resolvedRelativeUri.toString()); // Test relative with base not ending in / baseUri = new URI("http://localhost/base/directory"); assertEquals("http://localhost/base/directory/path/to/file", resolvedRelativeUri.toString()); }
28. TestAvatarStorageSetup#testSameSharedImageLocation()
View license@Test public void testSameSharedImageLocation() throws Exception { Configuration conf = new Configuration(); URI img0 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/"); URI img1 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/"); URI edit0 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/zero/"); URI edit1 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/one/"); conf.set("dfs.name.dir.shared0", img0.toString()); conf.set("dfs.name.dir.shared1", img1.toString()); conf.set("dfs.name.edits.dir.shared0", edit0.toString()); conf.set("dfs.name.edits.dir.shared1", edit1.toString()); // local locations for image and edits Collection<URI> namedirs = NNStorageConfiguration.getNamespaceDirs(conf, null); Collection<URI> editsdir = NNStorageConfiguration.getNamespaceEditsDirs(conf, null); try { AvatarStorageSetup.validate(conf, namedirs, editsdir, img0, img1, edit0, edit1); fail("fail of same shared image location"); } catch (IOException ex) { assertTrue(ex.getMessage().contains("same image location")); } }
29. TestAvatarStorageSetup#testSameSharedEditsLocation()
View license@Test public void testSameSharedEditsLocation() throws Exception { Configuration conf = new Configuration(); URI img0 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/zero/"); URI img1 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/one/"); URI edit0 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/"); URI edit1 = new URI("qjm://localhost:1234;localhost:1235;localhost:1236/test-id/"); conf.set("dfs.name.dir.shared0", img0.toString()); conf.set("dfs.name.dir.shared1", img1.toString()); conf.set("dfs.name.edits.dir.shared0", edit0.toString()); conf.set("dfs.name.edits.dir.shared1", edit1.toString()); // local locations for image and edits Collection<URI> namedirs = NNStorageConfiguration.getNamespaceDirs(conf, null); Collection<URI> editsdir = NNStorageConfiguration.getNamespaceEditsDirs(conf, null); try { AvatarStorageSetup.validate(conf, namedirs, editsdir, img0, img1, edit0, edit1); fail("fail of same shared eduts location"); } catch (IOException ex) { assertTrue(ex.getMessage().contains("same edits location")); } }
30. SimpleFlowTest#testFlowWithGlobalSession()
View license@Test public void testFlowWithGlobalSession() throws Exception { URI resource = getClass().getResource("/yaml/flow_using_global_session.yaml").toURI(); URI operation1 = getClass().getResource("/yaml/set_global_session_object.sl").toURI(); URI operation2 = getClass().getResource("/yaml/get_global_session_object.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("object_value", ValueFactory.create("SessionValue")); ScoreEvent event = trigger(compilationArtifact, userInputs, EMPTY_SET); Assert.assertEquals(ScoreLangConstants.EVENT_EXECUTION_FINISHED, event.getEventType()); }
31. DefaultServiceInstanceConverter#convert()
View license@Override public Application convert(ServiceInstance instance) { Application.Builder builder = Application.create(instance.getServiceId()); URI healthUrl = getHealthUrl(instance); if (healthUrl != null) { builder.withHealthUrl(healthUrl.toString()); } URI managementUrl = getManagementUrl(instance); if (managementUrl != null) { builder.withManagementUrl(managementUrl.toString()); } URI serviceUrl = getServiceUrl(instance); if (serviceUrl != null) { builder.withServiceUrl(serviceUrl.toString()); } return builder.build(); }
32. UriBuilderTest#testRelativize()
View license@Test public void testRelativize() throws Exception { URI from = URI.create("a/b/c"); URI to = URI.create("a/b/c/d/e"); URI relativized = ResteasyUriBuilder.relativize(from, to); Assert.assertEquals(relativized.toString(), "d/e"); from = URI.create("a/b/c"); to = URI.create("d/e"); relativized = ResteasyUriBuilder.relativize(from, to); Assert.assertEquals(relativized.toString(), "../../../d/e"); from = URI.create("a/b/c"); to = URI.create("a/b/c"); relativized = ResteasyUriBuilder.relativize(from, to); Assert.assertEquals(relativized.toString(), ""); from = URI.create("a"); to = URI.create("d/e"); relativized = ResteasyUriBuilder.relativize(from, to); Assert.assertEquals(relativized.toString(), "../d/e"); }
33. StoreResourceBean#head()
View licensepublic Response head(UriInfo uriInfo) { UriBuilder absolute = uriInfo.getBaseUriBuilder(); URI customerUrl = absolute.clone().path("customers").build(); URI orderUrl = absolute.clone().path("orders").build(); URI productUrl = absolute.clone().path("products").build(); javax.ws.rs.core.Link customers = javax.ws.rs.core.Link.fromUri(customerUrl).rel("customers").type("application/xml").build(); javax.ws.rs.core.Link orders = javax.ws.rs.core.Link.fromUri(orderUrl).rel("orders").type("application/xml").build(); javax.ws.rs.core.Link products = javax.ws.rs.core.Link.fromUri(productUrl).rel("products").type("application/xml").build(); Response.ResponseBuilder builder = Response.ok().links(customers, orders, products); return builder.build(); }
34. StoreResourceBean#head()
View licensepublic Response head(UriInfo uriInfo) { UriBuilder absolute = uriInfo.getBaseUriBuilder(); URI customerUrl = absolute.clone().path("customers").build(); URI orderUrl = absolute.clone().path("orders").build(); URI productUrl = absolute.clone().path("products").build(); Link customers = Link.fromUri(customerUrl).rel("customers").type("application/xml").build(); Link orders = Link.fromUri(orderUrl).rel("orders").type("application/xml").build(); Link products = Link.fromUri(productUrl).rel("products").type("application/xml").build(); Response.ResponseBuilder builder = Response.ok().links(customers, orders, products); return builder.build(); }
35. TransportBrokerTestSupport#createConnection()
View license@Override protected StubConnection createConnection() throws Exception { URI bindURI = getBindURI(); // Note: on platforms like OS X we cannot bind to the actual hostname, so we // instead use the original host name (typically localhost) to bind to URI actualURI = this.broker.getConnectURI(); URI connectURI = new URI(actualURI.getScheme(), actualURI.getUserInfo(), bindURI.getHost(), actualURI.getPort(), actualURI.getPath(), bindURI.getQuery(), bindURI.getFragment()); Transport transport = TransportFactory.connect(connectURI); StubConnection connection = new StubConnection(transport); connections.add(connection); return connection; }
36. ActiveMQConnectionFactoryTest#assertCreateConnection()
View licenseprotected void assertCreateConnection(String uri) throws Exception { // Start up a broker with a tcp connector. broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(false); TransportConnector connector = broker.addConnector(uri); broker.start(); URI temp = new URI(uri); // URI connectURI = connector.getServer().getConnectURI(); // TODO this sometimes fails when using the actual local host name URI currentURI = new URI(connector.getPublishableConnectString()); // sometimes the actual host name doesn't work in this test case // e.g. on OS X so lets use the original details but just use the actual // port URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), temp.getPath(), temp.getQuery(), temp.getFragment()); LOG.info("connection URI is: " + connectURI); // This should create the connection. ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI); connection = (ActiveMQConnection) cf.createConnection(); assertNotNull(connection); }
37. CompileBasicFlowTest#testValidFlowWithMissingDependencyRequiredInputInGrandchild()
View license@Test public void testValidFlowWithMissingDependencyRequiredInputInGrandchild() throws Exception { URI flowUri = getClass().getResource("/corrupted/flow_missing_dependency_required_input_in_grandchild.sl").toURI(); Executable flowModel = compiler.preCompile(SlangSource.fromFile(flowUri)); URI operation2Uri = getClass().getResource("/check_op.sl").toURI(); Executable operation2Model = compiler.preCompile(SlangSource.fromFile(operation2Uri)); URI subFlowUri = getClass().getResource("/flow_implicit_alias_for_current_namespace.sl").toURI(); Executable subFlowModel = compiler.preCompile(SlangSource.fromFile(subFlowUri)); Set<Executable> dependencies = new HashSet<>(); dependencies.add(subFlowModel); dependencies.add(operation2Model); List<RuntimeException> errors = compiler.validateSlangModelWithDirectDependencies(flowModel, dependencies); Assert.assertEquals(0, errors.size()); }
38. DefaultConfigurationResolverTest#testCacheManagerPropertiesOverridesSystemProperty()
View license@Test public void testCacheManagerPropertiesOverridesSystemProperty() throws Exception { URI uri1 = makeURI(); URI uri2 = makeURI(); assertFalse(uri1.equals(uri2)); Properties props = new Properties(); props.put(DefaultConfigurationResolver.DEFAULT_CONFIG_PROPERTY_NAME, uri1); System.getProperties().put(DefaultConfigurationResolver.DEFAULT_CONFIG_PROPERTY_NAME, uri2); URI resolved = DefaultConfigurationResolver.resolveConfigURI(props); assertSame(uri1, resolved); }
39. SimpleFlowTest#testFlowGetValue()
View license@Test public void testFlowGetValue() throws Exception { URI resource = getClass().getResource("/yaml/check_get_value.sl").toURI(); URI operation1 = getClass().getResource("/yaml/get_value.sl").toURI(); URI operation2 = getClass().getResource("/yaml/check_equal_types.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); Map<String, StepData> stepsData = triggerWithData(compilationArtifact, userInputs, EMPTY_SET).getSteps(); List<String> actualSteps = getStepsOnly(stepsData); Assert.assertEquals(2, actualSteps.size()); StepData firstStep = stepsData.get(FIRST_STEP_PATH); StepData secondStep = stepsData.get(SECOND_STEP_KEY); Assert.assertEquals("get_value", firstStep.getName()); Assert.assertEquals("SUCCESS", firstStep.getResult()); Assert.assertEquals("test_equality", secondStep.getName()); Assert.assertEquals("SUCCESS", secondStep.getResult()); }
40. SimpleFlowTest#testFlowWithSameInputNameAsStep()
View license@Test public void testFlowWithSameInputNameAsStep() throws Exception { URI resource = getClass().getResource("/yaml/flow_with_same_input_name_as_step.sl").toURI(); URI operation1 = getClass().getResource("/yaml/string_equals.sl").toURI(); URI operation2 = getClass().getResource("/yaml/test_op.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("first", ValueFactory.create("value")); userInputs.put("second_string", ValueFactory.create("value")); Map<String, StepData> stepsData = triggerWithData(compilationArtifact, userInputs, EMPTY_SET).getSteps(); List<String> actualSteps = getStepsOnly(stepsData); Assert.assertEquals(2, actualSteps.size()); StepData firstStep = stepsData.get(FIRST_STEP_PATH); StepData secondStep = stepsData.get(SECOND_STEP_KEY); Assert.assertEquals("CheckBinding", firstStep.getName()); Assert.assertEquals("StepOnSuccess", secondStep.getName()); }
41. SensitiveValueSyntaxInFlowTest#testValues()
View license@Test public void testValues() throws Exception { // compile URI resource = getClass().getResource("/yaml/sensitive/sensitive_values_flow.sl").toURI(); URI op1 = getClass().getResource("/yaml/noop.sl").toURI(); URI op2 = getClass().getResource("/yaml/print.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(op1), SlangSource.fromFile(op2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); // trigger Map<String, StepData> steps = prepareAndRun(compilationArtifact); // verify StepData flowData = steps.get(EXEC_START_PATH); StepData stepData = steps.get(FIRST_STEP_PATH); verifyInOutParams(flowData.getInputs()); verifyInOutParams(flowData.getOutputs()); verifyInOutParams(stepData.getInputs()); verifyInOutParams(stepData.getOutputs()); verifySuccessResult(flowData); }
42. SensitiveValuesInPythonExpressionsFlowTest#testValues()
View license@Test public void testValues() throws Exception { // compile URI resource = getClass().getResource("/yaml/sensitive/sensitive_values_in_python_expressions_flow.sl").toURI(); URI op1 = getClass().getResource("/yaml/noop.sl").toURI(); URI op2 = getClass().getResource("/yaml/print.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(op1), SlangSource.fromFile(op2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); // trigger Map<String, StepData> steps = prepareAndRun(compilationArtifact); // verify StepData flowData = steps.get(EXEC_START_PATH); StepData stepData = steps.get(FIRST_STEP_PATH); verifyInOutParams(flowData.getInputs()); verifyInOutParams(flowData.getOutputs()); verifyInOutParams(stepData.getInputs()); verifyInOutParams(stepData.getOutputs()); verifySuccessResult(flowData); }
43. ParallelLoopFlowsTest#testFlowWithParallelLoopPublishNavigate()
View license@Test public void testFlowWithParallelLoopPublishNavigate() throws Exception { URI resource = getClass().getResource("/yaml/loops/parallel_loop/parallel_loop_publish_navigate.sl").toURI(); URI operation1 = getClass().getResource("/yaml/loops/parallel_loop/print_branch.sl").toURI(); URI operation2 = getClass().getResource("/yaml/loops/parallel_loop/print_list.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); RuntimeInformation runtimeInformation = triggerWithData(SlangSource.fromFile(resource), path, getSystemProperties()); List<StepData> branchesData = extractParallelLoopData(runtimeInformation); Assert.assertEquals("incorrect number of branches", 3, branchesData.size()); List<String> expectedNameOutputs = verifyBranchPublishValues(branchesData); verifyPublishValues(runtimeInformation, expectedNameOutputs); verifyNavigation(runtimeInformation); }
44. ParallelLoopFlowsTest#testFlowWithParallelLoopNavigate()
View license@Test public void testFlowWithParallelLoopNavigate() throws Exception { URI resource = getClass().getResource("/yaml/loops/parallel_loop/parallel_loop_navigate.sl").toURI(); URI operation1 = getClass().getResource("/yaml/loops/parallel_loop/print_branch.sl").toURI(); URI operation2 = getClass().getResource("/yaml/loops/parallel_loop/print_list.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); RuntimeInformation runtimeInformation = triggerWithData(SlangSource.fromFile(resource), path); List<StepData> branchesData = extractParallelLoopData(runtimeInformation); Assert.assertEquals("incorrect number of branches", 3, branchesData.size()); verifyNavigation(runtimeInformation); }
45. LoopFlowsTest#testFlowWithMapLoopsWithBreak()
View license@Test public void testFlowWithMapLoopsWithBreak() throws Exception { URI resource = getClass().getResource("/yaml/loops/loop_with_break_with_map.sl").toURI(); URI operation1 = getClass().getResource("/yaml/loops/operation_that_goes_to_custom_when_value_is_2.sl").toURI(); URI operation2 = getClass().getResource("/yaml/loops/print.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); Map<String, StepData> stepsData = triggerWithData(compilationArtifact, userInputs, EMPTY_SET).getSteps(); List<String> actualSteps = getStepsOnly(stepsData); Assert.assertEquals(2, actualSteps.size()); StepData secondStep = stepsData.get(SECOND_STEP_KEY); Assert.assertEquals("print_other_values", secondStep.getName()); }
46. LoopFlowsTest#testFlowWithLoopsWithBreak()
View license@Test public void testFlowWithLoopsWithBreak() throws Exception { URI resource = getClass().getResource("/yaml/loops/loop_with_break.sl").toURI(); URI operation1 = getClass().getResource("/yaml/loops/operation_that_goes_to_custom_when_value_is_2.sl").toURI(); URI operation2 = getClass().getResource("/yaml/loops/print.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); Map<String, StepData> stepsData = triggerWithData(compilationArtifact, userInputs, EMPTY_SET).getSteps(); List<String> actualSteps = getStepsOnly(stepsData); Assert.assertEquals(3, actualSteps.size()); StepData thirdStep = stepsData.get(THIRD_STEP_KEY); Assert.assertEquals("print_other_values", thirdStep.getName()); }
47. FlowWithJavaVersioningTest#testFlowWithGlobalSession()
View license@Test public void testFlowWithGlobalSession() throws Exception { Assume.assumeTrue(shouldRunMaven); URI resource = getClass().getResource("/yaml/versioning/testglobals/flow_using_global_session_dependencies.sl").toURI(); URI operation1 = getClass().getResource("/yaml/versioning/testglobals/set_global_session_object_dependencies.sl").toURI(); URI operation2 = getClass().getResource("/yaml/versioning/testglobals/get_global_session_object_dependencies.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(operation1), SlangSource.fromFile(operation2)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("object_value", ValueFactory.create("SessionValue")); ScoreEvent event = trigger(compilationArtifact, userInputs, Collections.<SystemProperty>emptySet()); Assert.assertEquals(ScoreLangConstants.EVENT_EXECUTION_FINISHED, event.getEventType()); LanguageEventData data = (LanguageEventData) event.getData(); Serializable result_object_value = data.getOutputs().get("result_object_value"); assertEquals("SessionValue", result_object_value); }
48. ValueSyntaxInFlowTest#testValues()
View license@Test public void testValues() throws Exception { // compile URI resource = getClass().getResource("/yaml/formats/values_flow.sl").toURI(); URI operation1 = getClass().getResource("/yaml/formats/values_op.sl").toURI(); URI operation2 = getClass().getResource("/yaml/noop.sl").toURI(); SlangSource dep1 = SlangSource.fromFile(operation1); SlangSource dep2 = SlangSource.fromFile(operation2); Set<SlangSource> path = Sets.newHashSet(dep1, dep2); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); // trigger Map<String, StepData> steps = prepareAndRun(compilationArtifact); // verify StepData flowData = steps.get(EXEC_START_PATH); StepData stepData = steps.get(FIRST_STEP_PATH); verifyExecutableInputs(flowData); verifyExecutableOutputs(flowData); verifyStepInputs(stepData); verifyStepPublishValues(stepData); verifySuccessResult(flowData); }
49. NavigationTest#testNavigationOnFailureContainsStepWithCustomResult()
View license@Test public void testNavigationOnFailureContainsStepWithCustomResult() throws Exception { URI resource = getClass().getResource("/yaml/on_failure_contains_step_with_custom_result.sl").toURI(); URI flow1 = getClass().getResource("/yaml/flow_with_custom_result.sl").toURI(); URI operation1 = getClass().getResource("/yaml/test_op.sl").toURI(); Set<SlangSource> path = Sets.newHashSet(SlangSource.fromFile(flow1), SlangSource.fromFile(operation1)); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Value> userInputs = new HashMap<>(); userInputs.put("alla", ValueFactory.create("alla message 1")); Map<String, StepData> steps = triggerWithData(compilationArtifact, userInputs, new HashSet<SystemProperty>()).getSteps(); Assert.assertEquals("on_failure_contains_step_with_custom_result", steps.get(EXEC_START_PATH).getName()); Assert.assertEquals(ScoreLangConstants.FAILURE_RESULT, steps.get(EXEC_START_PATH).getResult()); Assert.assertEquals("print_message1", steps.get(FIRST_STEP_PATH).getName()); Assert.assertEquals(ScoreLangConstants.SUCCESS_RESULT, steps.get(FIRST_STEP_PATH).getResult()); Assert.assertEquals("print_on_failure_1", steps.get(SECOND_STEP_KEY).getName()); Assert.assertEquals(ScoreLangConstants.FAILURE_RESULT, steps.get(SECOND_STEP_KEY).getResult()); Assert.assertEquals("print_message1_flow_with_custom_result", steps.get("0.1.0").getName()); Assert.assertEquals("CUSTOM_SUCCESS", steps.get("0.1.0").getResult()); }
50. CompilerErrorsTest#testValidationOfFlowWithMissingDependencyRequiredInputInStep()
View license@Test public void testValidationOfFlowWithMissingDependencyRequiredInputInStep() throws Exception { URI flowUri = getClass().getResource("/corrupted/flow_missing_dependency_required_input_in_step.sl").toURI(); Executable flowModel = compiler.preCompile(SlangSource.fromFile(flowUri)); URI operation1Uri = getClass().getResource("/test_op.sl").toURI(); Executable operation1Model = compiler.preCompile(SlangSource.fromFile(operation1Uri)); URI operation2Uri = getClass().getResource("/check_op.sl").toURI(); Executable operation2Model = compiler.preCompile(SlangSource.fromFile(operation2Uri)); Set<Executable> dependencies = new HashSet<>(); dependencies.add(operation1Model); dependencies.add(operation2Model); exception.expect(IllegalArgumentException.class); exception.expectMessage("Cannot compile flow 'io.cloudslang.flow_missing_dependency_required_input_in_step'. " + "Step 'explicit_alias' does not declare all the mandatory inputs of its reference. " + "The following inputs of 'user.ops.test_op' are not private, required and with no default value: alla."); List<RuntimeException> errors = compiler.validateSlangModelWithDirectDependencies(flowModel, dependencies); Assert.assertEquals(1, errors.size()); throw errors.get(0); }
51. CompilerErrorsTest#testFlowWithCorruptedKeyInImports()
View license@Test public void testFlowWithCorruptedKeyInImports() throws Exception { //covers problem parsing YAML source "while scanning a simple key" URI resource = getClass().getResource("/corrupted/flow_with_corrupted_key_in_imports.sl").toURI(); URI operations = getClass().getResource("/java_op.sl").toURI(); URI flows = getClass().getResource("/flow_with_data.yaml").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operations)); path.add(SlangSource.fromFile(flows)); exception.expect(RuntimeException.class); exception.expectMessage(ParserExceptionHandler.SCANNING_A_SIMPLE_KEY_ERROR); exception.expectMessage(ParserExceptionHandler.KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG); compiler.compile(SlangSource.fromFile(resource), path); }
52. CompilerErrorsTest#testSystemPropertiesAsDep()
View license@Test public void testSystemPropertiesAsDep() throws Exception { URI flow = getClass().getResource("/basic_flow.yaml").toURI(); URI operation = getClass().getResource("/test_op.sl").toURI(); URI systemProperties = getClass().getResource("/corrupted/system_properties.yaml").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operation)); path.add(SlangSource.fromFile(systemProperties)); exception.expect(RuntimeException.class); exception.expectMessage("There was a problem parsing the YAML source: system_properties.\n" + "Cannot create property=user.sys.props.host for JavaBean=io.cloudslang.lang.compiler.parser.model.ParsedSlang"); compiler.compile(SlangSource.fromFile(flow), path); }
53. CompileParallelLoopFlowTest#testAggregateKeyThrowsException()
View license@Test public void testAggregateKeyThrowsException() throws Exception { URI flow = getClass().getResource("/corrupted/loops/parallel_loop/parallel_loop_aggregate_key.sl").toURI(); URI operation1 = getClass().getResource("/loops/parallel_loop/print_branch.sl").toURI(); URI operation2 = getClass().getResource("/loops/parallel_loop/print_list.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operation1)); path.add(SlangSource.fromFile(operation2)); expectedException.expect(RuntimeException.class); expectedException.expectMessage("Artifact {print_values} has unrecognized tag {aggregate}. " + "Please take a look at the supported features per versions link"); compiler.compile(SlangSource.fromFile(flow), path); }
54. CompileParallelLoopFlowTest#testPublishOnBranchThrowsException()
View license@Test public void testPublishOnBranchThrowsException() throws Exception { URI flow = getClass().getResource("/corrupted/loops/parallel_loop/parallel_loop_publish_on_branch.sl").toURI(); URI operation1 = getClass().getResource("/loops/parallel_loop/print_branch.sl").toURI(); URI operation2 = getClass().getResource("/loops/parallel_loop/print_list.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(operation1)); path.add(SlangSource.fromFile(operation2)); expectedException.expect(RuntimeException.class); expectedException.expectMessage("Artifact {print_values} has unrecognized tag {publish} under 'parallel_loop'. " + "Please take a look at the supported features per versions link"); compiler.compile(SlangSource.fromFile(flow), path); }
55. CompileDependenciesTest#circularDependencies()
View license@Test public void circularDependencies() throws Exception { URI flow = getClass().getResource("/circular-dependencies/circular_parent_flow.yaml").toURI(); URI child_flow = getClass().getResource("/circular-dependencies/circular_child_flow.yaml").toURI(); URI operation = getClass().getResource("/test_op.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(child_flow)); path.add(SlangSource.fromFile(operation)); CompilationArtifact compilationArtifact = compiler.compile(SlangSource.fromFile(flow), path); ExecutionPlan executionPlan = compilationArtifact.getExecutionPlan(); Assert.assertNotNull(executionPlan); Assert.assertEquals(3, compilationArtifact.getDependencies().size()); }
56. CompileDependenciesTest#bothFileAreDependentOnTheSameFile()
View license@Test public void bothFileAreDependentOnTheSameFile() throws Exception { URI flow = getClass().getResource("/circular-dependencies/parent_flow.yaml").toURI(); URI child_flow = getClass().getResource("/circular-dependencies/child_flow.yaml").toURI(); URI operation = getClass().getResource("/test_op.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(child_flow)); path.add(SlangSource.fromFile(operation)); CompilationArtifact compilationArtifact = compiler.compile(SlangSource.fromFile(flow), path); ExecutionPlan executionPlan = compilationArtifact.getExecutionPlan(); Assert.assertNotNull(executionPlan); Assert.assertEquals("different number of dependencies than expected", 2, compilationArtifact.getDependencies().size()); }
57. CompileDependenciesTest#subFlowRefId()
View license@Test public void subFlowRefId() throws Exception { URI flow = getClass().getResource("/circular-dependencies/parent_flow.yaml").toURI(); URI child_flow = getClass().getResource("/circular-dependencies/child_flow.yaml").toURI(); URI operation = getClass().getResource("/test_op.sl").toURI(); Set<SlangSource> path = new HashSet<>(); path.add(SlangSource.fromFile(child_flow)); path.add(SlangSource.fromFile(operation)); CompilationArtifact compilationArtifact = compiler.compile(SlangSource.fromFile(flow), path); ExecutionPlan executionPlan = compilationArtifact.getExecutionPlan(); Assert.assertNotNull(executionPlan); Assert.assertEquals("different number of dependencies than expected", 2, compilationArtifact.getDependencies().size()); ExecutionStep secondStepStartExecutionStep = executionPlan.getStep(4L); String refId = (String) secondStepStartExecutionStep.getActionData().get(ScoreLangConstants.REF_ID); Assert.assertEquals("refId is not as expected", "user.flows.circular.child_flow", refId); }
58. CompilerErrorsTest#testValidationOfFlowInputInStepWithSameNameAsDependencyOutput()
View license@Test public void testValidationOfFlowInputInStepWithSameNameAsDependencyOutput() throws Exception { URI flowUri = getClass().getResource("/corrupted/flow_input_in_step_same_name_as_dependency_output.sl").toURI(); Executable flowModel = compiler.preCompile(SlangSource.fromFile(flowUri)); URI operation1Uri = getClass().getResource("/test_op.sl").toURI(); Executable operation1Model = compiler.preCompile(SlangSource.fromFile(operation1Uri)); URI operation2Uri = getClass().getResource("/check_op.sl").toURI(); Executable operation2Model = compiler.preCompile(SlangSource.fromFile(operation2Uri)); Set<Executable> dependencies = new HashSet<>(); dependencies.add(operation1Model); dependencies.add(operation2Model); exception.expect(IllegalArgumentException.class); exception.expectMessage("Cannot compile flow 'io.cloudslang.flow_input_in_step_same_name_as_dependency_output'. " + "Step 'explicit_alias' has input 'balla' with the same name as the one of the outputs of 'user.ops.test_op'."); List<RuntimeException> errors = compiler.validateSlangModelWithDirectDependencies(flowModel, dependencies); Assert.assertEquals(1, errors.size()); throw errors.get(0); }
59. FileSet#isIncluded()
View licensepublic boolean isIncluded(File file) { URI target = file.toURI(); URI source = base.toURI(); URI relative = source.relativize(target); if (relative.equals(target) || relative.equals(source)) return false; String[] segments = relative.getPath().split("/"); if (dfa.isIncluded(segments, 0)) return true; return false; }
60. HadoopDataSourceUtil#contains()
View license/** * Returns whether the parent path contains the child path, or not. * If the parent and child is same, this returns {@code false}. * @param parent the parent path * @param child the child path * @return {@code true} if parent path strictly contains the child, otherwise {@code false} * @throws IllegalArgumentException if some parameters were {@code null} */ public static boolean contains(Path parent, Path child) { if (parent == null) { //$NON-NLS-1$ throw new IllegalArgumentException("parent must not be null"); } if (child == null) { //$NON-NLS-1$ throw new IllegalArgumentException("child must not be null"); } if (parent.depth() >= child.depth()) { return false; } URI parentUri = parent.toUri(); URI childUri = child.toUri(); URI relative = parentUri.relativize(childUri); if (relative.equals(childUri) == false) { return true; } return false; }
61. TestRegisterParser#testRegisterArtifact()
View license// Test to check if all dependencies are successfully added to the classpath @Test public void testRegisterArtifact() throws URISyntaxException, IOException, ParserException { URI[] list = new URI[5]; list[0] = new URI(TEST_JAR_DIR + "testjar-1.jar"); list[1] = new URI(TEST_JAR_DIR + "testjar-2.jar"); list[2] = new URI(TEST_JAR_DIR + "testjar-3.jar"); list[3] = new URI(TEST_JAR_DIR + "testjar-4.jar"); list[4] = new URI(TEST_JAR_DIR + "testjar-5.jar"); // Make sure that the jars are not in the classpath for (URI dependency : list) { Assert.assertFalse(pigServer.getPigContext().hasJar(dependency.toString())); } RegisterResolver registerResolver = Mockito.spy(new RegisterResolver(pigServer)); Mockito.doReturn(list).when(registerResolver).resolve(new URI("ivy://testQuery")); registerResolver.parseRegister("ivy://testQuery", null, null); for (URI dependency : list) { Assert.assertTrue(pigServer.getPigContext().hasJar(dependency.toString())); } }
62. MultiReleaseJarTest#initialize()
View license@BeforeClass public void initialize() throws Exception { CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars(); creator.compileEntries(); creator.buildUnversionedJar(); creator.buildMultiReleaseJar(); creator.buildShortMultiReleaseJar(); String ssp = Paths.get(userdir, "unversioned.jar").toUri().toString(); uvuri = new URI("jar", ssp, null); ssp = Paths.get(userdir, "multi-release.jar").toUri().toString(); mruri = new URI("jar", ssp, null); ssp = Paths.get(userdir, "short-multi-release.jar").toUri().toString(); smruri = new URI("jar", ssp, null); entryName = className.replace('.', '/') + ".class"; }
63. WindowsPathTypeTest#testWindows_toUri_normal()
View license@Test public void testWindows_toUri_normal() { URI fileUri = PathType.windows().toUri(fileSystemUri, "C:\\", ImmutableList.of("foo", "bar"), false); assertThat(fileUri.toString()).isEqualTo("jimfs://foo/C:/foo/bar"); assertThat(fileUri.getPath()).isEqualTo("/C:/foo/bar"); URI directoryUri = PathType.windows().toUri(fileSystemUri, "C:\\", ImmutableList.of("foo", "bar"), true); assertThat(directoryUri.toString()).isEqualTo("jimfs://foo/C:/foo/bar/"); assertThat(directoryUri.getPath()).isEqualTo("/C:/foo/bar/"); URI rootUri = PathType.windows().toUri(fileSystemUri, "C:\\", ImmutableList.<String>of(), true); assertThat(rootUri.toString()).isEqualTo("jimfs://foo/C:/"); assertThat(rootUri.getPath()).isEqualTo("/C:/"); }
64. UnixPathTypeTest#testUnix_toUri()
View license@Test public void testUnix_toUri() { URI fileUri = PathType.unix().toUri(fileSystemUri, "/", ImmutableList.of("foo", "bar"), false); assertThat(fileUri.toString()).isEqualTo("jimfs://foo/foo/bar"); assertThat(fileUri.getPath()).isEqualTo("/foo/bar"); URI directoryUri = PathType.unix().toUri(fileSystemUri, "/", ImmutableList.of("foo", "bar"), true); assertThat(directoryUri.toString()).isEqualTo("jimfs://foo/foo/bar/"); assertThat(directoryUri.getPath()).isEqualTo("/foo/bar/"); URI rootUri = PathType.unix().toUri(fileSystemUri, "/", ImmutableList.<String>of(), true); assertThat(rootUri.toString()).isEqualTo("jimfs://foo/"); assertThat(rootUri.getPath()).isEqualTo("/"); }
65. PathTypeTest#testToUri()
View license@Test public void testToUri() { URI fileUri = type.toUri(fileSystemUri, "$", ImmutableList.of("foo", "bar"), false); assertThat(fileUri.toString()).isEqualTo("jimfs://foo/$/foo/bar"); assertThat(fileUri.getPath()).isEqualTo("/$/foo/bar"); URI directoryUri = type.toUri(fileSystemUri, "$", ImmutableList.of("foo", "bar"), true); assertThat(directoryUri.toString()).isEqualTo("jimfs://foo/$/foo/bar/"); assertThat(directoryUri.getPath()).isEqualTo("/$/foo/bar/"); URI rootUri = type.toUri(fileSystemUri, "$", ImmutableList.<String>of(), true); assertThat(rootUri.toString()).isEqualTo("jimfs://foo/$/"); assertThat(rootUri.getPath()).isEqualTo("/$/"); }
66. WebURL#resolve()
View licensepublic WebURL resolve(String raw) throws URISyntaxException { URI rawURL = new URI(raw); if (rawURL.isAbsolute()) return new WebURL(rawURL); URI fixedURL = theURL; if (theURL.getPath() == null || theURL.getPath().length() == 0) fixedURL = new URI(theURL.getScheme(), null, theURL.getHost(), theURL.getPort(), "/", null, null); if (raw.startsWith("?")) return new WebURL(fixedURL.getScheme(), fixedURL.getHost(), fixedURL.getPort(), fixedURL.getPath(), rawURL.getRawQuery()); return new WebURL(fixedURL.resolve(rawURL)); }
67. WebURL#resolve()
View licensepublic WebURL resolve(String raw) throws URISyntaxException { URI rawURL = new URI(raw); if (rawURL.isAbsolute()) return new WebURL(rawURL); URI fixedURL = theURL; if (theURL.getPath() == null || theURL.getPath().length() == 0) fixedURL = new URI(theURL.getScheme(), null, theURL.getHost(), theURL.getPort(), "/", null, null); if (raw.startsWith("?")) return new WebURL(fixedURL.getScheme(), fixedURL.getHost(), fixedURL.getPort(), fixedURL.getPath(), rawURL.getRawQuery()); return new WebURL(fixedURL.resolve(rawURL)); }
68. Delombok#createFileWriter()
View licenseprivate Writer createFileWriter(File outBase, File inBase, URI file) throws IOException { URI base = inBase.toURI(); URI relative = base.relativize(base.resolve(file)); File outFile; if (relative.isAbsolute()) { outFile = new File(outBase, new File(relative).getName()); } else { outFile = new File(outBase, relative.getPath()); } outFile.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(outFile); return createUnicodeEscapeWriter(out); }
69. TestDefaultNameNodePort#testGetAddressFromConf()
View license@Test public void testGetAddressFromConf() throws Exception { Configuration conf = new Configuration(); FileSystem.setDefaultUri(conf, "hdfs://foo/"); URI uri = new URI(null, NameNode.getDefaultAddress(conf), null, null, null); assertEquals(-1, uri.getPort()); FileSystem.setDefaultUri(conf, "hdfs://foo:555"); uri = new URI(null, NameNode.getDefaultAddress(conf), null, null, null); assertEquals(555, uri.getPort()); FileSystem.setDefaultUri(conf, "foo"); uri = new URI(null, NameNode.getDefaultAddress(conf), null, null, null); assertEquals(-1, uri.getPort()); }
70. URIResultInfoRetriever#retrieveSupplementalInfo()
View license@Override void retrieveSupplementalInfo() throws IOException { URI oldURI; try { oldURI = new URI(result.getURI()); } catch (URISyntaxException e) { return; } URI newURI = HttpHelper.unredirect(oldURI); int count = 0; while (count++ < MAX_REDIRECTS && !oldURI.equals(newURI)) { append(result.getDisplayResult(), null, new String[] { redirectString + " : " + newURI }, newURI.toString()); oldURI = newURI; newURI = HttpHelper.unredirect(newURI); } }
71. URIResultInfoRetriever#retrieveSupplementalInfo()
View license@Override void retrieveSupplementalInfo() throws IOException { URI oldURI; try { oldURI = new URI(result.getURI()); } catch (URISyntaxException e) { return; } URI newURI = HttpHelper.unredirect(oldURI); int count = 0; while (count++ < MAX_REDIRECTS && !oldURI.equals(newURI)) { append(result.getDisplayResult(), null, new String[] { redirectString + " : " + newURI }, newURI.toString()); oldURI = newURI; newURI = HttpHelper.unredirect(newURI); } }
72. URIResultInfoRetriever#retrieveSupplementalInfo()
View license@Override void retrieveSupplementalInfo() throws IOException { URI oldURI; try { oldURI = new URI(result.getURI()); } catch (URISyntaxException e) { return; } URI newURI = HttpHelper.unredirect(oldURI); int count = 0; while (count++ < MAX_REDIRECTS && !oldURI.equals(newURI)) { append(result.getDisplayResult(), null, new String[] { redirectString + " : " + newURI }, newURI.toString()); oldURI = newURI; newURI = HttpHelper.unredirect(newURI); } }
73. FileUtilsTest#testFileExistsWithPlusCharactersInName()
View license/** * Helps figure out why {@link #testFileFromUriWithPlusCharactersInName()} fails in Jenkins but asserting different * parts of the implementation of {@link FileUtils#fileFromUri(URI)}. */ @Test public void testFileExistsWithPlusCharactersInName() throws Exception { final String config = "target/test-classes/log4j+config+with+plus+characters.xml"; final File file = new File(config); assertEquals(LOG4J_CONFIG_WITH_PLUS, file.getName()); assertTrue("file exists", file.exists()); // final URI uri1 = new URI(config); assertNull(uri1.getScheme()); // final URI uri2 = new File(uri1.getPath()).toURI(); assertNotNull(uri2); assertTrue("URI \"" + uri2 + "\" does not end with \"" + LOG4J_CONFIG_WITH_PLUS + "\"", uri2.toString().endsWith(LOG4J_CONFIG_WITH_PLUS)); // final String fileName = uri2.toURL().getFile(); assertTrue("File name \"" + fileName + "\" does not end with \"" + LOG4J_CONFIG_WITH_PLUS + "\"", fileName.endsWith(LOG4J_CONFIG_WITH_PLUS)); }
74. ProfileElement#addToModel()
View license/** * Add this element to an RDF model including this element's profile. * * @param model The model to which we're being added. * @param resource The profile as an RDF resource description. * @param profAttr The profile's attributes. */ void addToModel(Model model, Resource resource, ProfileAttributes profAttr) { URI profileURI = profile.getURI(); URI myURI = URI.create(profileURI.toString() + "#" + name); Resource element = model.createResource(myURI.toString()); Utility.addProperty(model, resource, Utility.edmElement, element, profAttr, myURI); String obStr = obligation ? "Required" : "Optional"; String occurStr = String.valueOf(maxOccurrence); Utility.addProperty(model, element, Utility.edmElemID, id, profAttr, myURI); Utility.addProperty(model, element, Utility.edmDescription, desc, profAttr, myURI); Utility.addProperty(model, element, Utility.edmElemType, type, profAttr, myURI); Utility.addProperty(model, element, Utility.edmUnit, unit, profAttr, myURI); Utility.addProperty(model, element, Utility.edmSynonym, synonyms, profAttr, myURI); Utility.addProperty(model, element, Utility.edmObligation, obStr, profAttr, myURI); Utility.addProperty(model, element, Utility.edmMaxOccurrence, occurStr, profAttr, myURI); Utility.addProperty(model, element, Utility.edmComment, comments, profAttr, myURI); addElementSpecificProperties(model, element, profAttr, myURI); }
75. URIUtils#getURI()
View license/** * Build URI starting from the given base and href. * <br/> * If href is absolute or base is null then base will be ignored. * * @param base URI prefix. * @param href URI suffix. * @return built URI. */ public static URI getURI(final URI base, final String href) { if (href == null) { throw new IllegalArgumentException("Null link provided"); } URI uri = URI.create(href); if (!uri.isAbsolute() && base != null) { uri = URI.create(base.toASCIIString() + "/" + href); } return uri.normalize(); }
76. URIUtils#getURI()
View license/** * Build URI starting from the given base and href. * <br/> * If href is absolute or base is null then base will be ignored. * * @param base URI prefix. * @param href URI suffix. * @return built URI. */ public static URI getURI(final String base, final String href) { if (href == null) { throw new IllegalArgumentException("Null link provided"); } URI uri = URI.create(href); if (!uri.isAbsolute() && base != null) { uri = URI.create(base + "/" + href); } return uri.normalize(); }
77. ClientLink#getURI()
View license/** * Build URI starting from the given base and href. * <br/> * If href is absolute or base is null then base will be ignored. * * @param base URI prefix. * @param href URI suffix. * @return built URI. */ private static URI getURI(final URI base, final String href) { if (href == null) { throw new IllegalArgumentException("Null link provided"); } URI uri = URI.create(href); if (!uri.isAbsolute() && base != null) { uri = URI.create(base.toASCIIString() + "/" + href); } return uri.normalize(); }
78. EntityReferencesITCase#updateMissingNavigationProperty()
View license@Test public void updateMissingNavigationProperty() throws Exception { final ODataClient client = getClient(); final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendRefSegment().build(); final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build(); try { client.getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, ref).execute(); } catch (ODataClientErrorException e) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode()); } }
79. EntityReferencesITCase#createMissingNavigationProperty()
View license@Test public void createMissingNavigationProperty() throws Exception { final ODataClient client = getClient(); final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendRefSegment().build(); final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build(); try { client.getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, ref).execute(); } catch (ODataClientErrorException e) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode()); } }
80. EntityReferencesITCase#createReferenceToPrimitiveProperty()
View license@Test public void createReferenceToPrimitiveProperty() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(PROPERTY_INT16).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build(); try { getEdmEnabledClient().getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
81. EntityReferencesITCase#updateReferenceToPrimitiveProperty()
View license@Test public void updateReferenceToPrimitiveProperty() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(PROPERTY_INT16).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build(); try { getClient().getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
82. EntityReferencesITCase#updateReferenceNull()
View license@Test public void updateReferenceNull() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_ONE).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(INVALID_HOST).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build(); try { getClient().getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
83. EntityReferencesITCase#updateReferenceInvalidHost()
View license@Test public void updateReferenceInvalidHost() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_ONE).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(INVALID_HOST).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build(); try { getClient().getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
84. EntityReferencesITCase#updateReferenceNotExistingEntityId()
View license@Test public void updateReferenceNotExistingEntityId() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_ONE).appendRefSegment().build(); final URI reference = new URI(ES_KEY_NAV + "(42)"); try { getClient().getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
85. EntityReferencesITCase#updateReferenceInvalidEntityID()
View license@Test public void updateReferenceInvalidEntityID() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_ONE).appendRefSegment().build(); final URI reference = new URI("NonExistingEntity" + "(3)"); try { getClient().getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
86. EntityReferencesITCase#createReferenceInvalidHost()
View license@Test public void createReferenceInvalidHost() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_MANY).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(INVALID_HOST).appendEntitySetSegment("NotExisting").build(); try { getClient().getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
87. EntityReferencesITCase#createReferenceInvalidEntityId()
View license@Test public void createReferenceInvalidEntityId() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_MANY).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("NotExisting").build(); try { getClient().getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
88. EntityReferencesITCase#createReferenceNonExistingEntityId()
View license@Test public void createReferenceNonExistingEntityId() throws Exception { final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_MANY).appendRefSegment().build(); final URI reference = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(35).build(); try { getClient().getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, reference).execute(); fail(); } catch (ODataClientErrorException ex) { assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), ex.getStatusLine().getStatusCode()); } }
89. BasicITCase#createEntityWithIEEE754CompatibleParameterNull()
View license@Test public void createEntityWithIEEE754CompatibleParameterNull() { assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson()); final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(); final URI linkURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).appendKeySegment(32767).build(); final ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM); newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64, getFactory().newPrimitiveValueBuilder().buildInt64(null))); newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_DECIMAL, getFactory().newPrimitiveValueBuilder().buildDecimal(null))); newEntity.addLink(getFactory().newEntityNavigationLink(NAV_PROPERTY_ET_TWO_PRIM_ONE, linkURI)); final ODataEntityCreateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory().getEntityCreateRequest(uri, newEntity); request.setContentType(CONTENT_TYPE_JSON_IEEE754_COMPATIBLE); request.setAccept(CONTENT_TYPE_JSON_IEEE754_COMPATIBLE); final ODataEntityCreateResponse<ClientEntity> response = request.execute(); assertTrue(response.getBody().getProperty(PROPERTY_INT64).hasNullValue()); assertTrue(response.getBody().getProperty(PROPERTY_DECIMAL).hasNullValue()); }
90. BasicITCase#createEntityWithIEEE754CompatibleParameter()
View license@Test public void createEntityWithIEEE754CompatibleParameter() { assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson()); final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(); final URI linkURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).appendKeySegment(32767).build(); final ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM); newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64, getFactory().newPrimitiveValueBuilder().buildInt64(Long.MAX_VALUE))); newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_DECIMAL, getFactory().newPrimitiveValueBuilder().buildDecimal(BigDecimal.valueOf(34)))); newEntity.addLink(getFactory().newEntityNavigationLink(NAV_PROPERTY_ET_TWO_PRIM_ONE, linkURI)); final ODataEntityCreateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory().getEntityCreateRequest(uri, newEntity); request.setContentType(CONTENT_TYPE_JSON_IEEE754_COMPATIBLE); request.setAccept(CONTENT_TYPE_JSON_IEEE754_COMPATIBLE); final ODataEntityCreateResponse<ClientEntity> response = request.execute(); assertEquals(Long.MAX_VALUE, response.getBody().getProperty(PROPERTY_INT64).getPrimitiveValue().toValue()); assertEquals(BigDecimal.valueOf(34), response.getBody().getProperty(PROPERTY_DECIMAL).getPrimitiveValue().toValue()); }
91. AccountSetupAccountType#setupDav()
View licenseprivate void setupDav() throws URISyntaxException { URI uriForDecode = new URI(mAccount.getStoreUri()); /* * The user info we have been given from * AccountSetupBasics.onManualSetup() is encoded as an IMAP store * URI: AuthType:UserName:Password (no fields should be empty). * However, AuthType is not applicable to WebDAV nor to its store * URI. Re-encode without it, using just the UserName and Password. */ String userPass = ""; String[] userInfo = uriForDecode.getUserInfo().split(":"); if (userInfo.length > 1) { userPass = userInfo[1]; } if (userInfo.length > 2) { userPass = userPass + ":" + userInfo[2]; } URI uri = new URI("webdav+ssl+", userPass, uriForDecode.getHost(), uriForDecode.getPort(), null, null, null); mAccount.setStoreUri(uri.toString()); }
92. WindowsPathTypeTest#testWindows_toUri_unc()
View license@Test public void testWindows_toUri_unc() { URI fileUri = PathType.windows().toUri(fileSystemUri, "\\\\host\\share\\", ImmutableList.of("foo", "bar"), false); assertThat(fileUri.toString()).isEqualTo("jimfs://foo//host/share/foo/bar"); assertThat(fileUri.getPath()).isEqualTo("//host/share/foo/bar"); URI rootUri = PathType.windows().toUri(fileSystemUri, "\\\\host\\share\\", ImmutableList.<String>of(), true); assertThat(rootUri.toString()).isEqualTo("jimfs://foo//host/share/"); assertThat(rootUri.getPath()).isEqualTo("//host/share/"); }
93. FileOutputCommitter#getFinalPath()
View licenseprivate Path getFinalPath(Path jobOutputDir, Path taskOutput, Path taskOutputPath) throws IOException { URI taskOutputUri = taskOutput.toUri(); URI relativePath = taskOutputPath.toUri().relativize(taskOutputUri); if (taskOutputUri == relativePath) { //taskOutputPath is not a parent of taskOutput throw new IOException("Can not get the relative path: base = " + taskOutputPath + " child = " + taskOutput); } if (relativePath.getPath().length() > 0) { return new Path(jobOutputDir, relativePath.getPath()); } else { return jobOutputDir; } }
94. IgniteHadoopFileSystem#checkPath()
View license/** {@inheritDoc} */ @Override protected void checkPath(Path path) { URI uri = path.toUri(); if (uri.isAbsolute()) { if (!F.eq(uri.getScheme(), IGFS_SCHEME)) throw new InvalidPathException("Wrong path scheme [expected=" + IGFS_SCHEME + ", actual=" + uri.getAuthority() + ']'); if (!F.eq(uri.getAuthority(), uriAuthority)) throw new InvalidPathException("Wrong path authority [expected=" + uriAuthority + ", actual=" + uri.getAuthority() + ']'); } }
95. AbstractHttpAsyncClient#determineTarget()
View licenseprivate HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException { // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in the director. HttpHost target = null; URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); if (target == null) { throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI); } } return target; }
96. HCatOutputCommitter#getFinalPath()
View license/** * Find the final name of a given output file, given the output directory * and the work directory. * @param file the file to move * @param src the source directory * @param dest the target directory * @return the final path for the specific output file * @throws IOException */ private Path getFinalPath(Path file, Path src, Path dest) throws IOException { URI taskOutputUri = file.toUri(); URI relativePath = src.toUri().relativize(taskOutputUri); if (taskOutputUri == relativePath) { throw new HCatException(ErrorType.ERROR_MOVE_FAILED, "Can not get the relative path: base = " + src + " child = " + file); } if (relativePath.getPath().length() > 0) { return new Path(dest, relativePath.getPath()); } else { return dest; } }
97. UriDt#normalize()
View licenseprivate String normalize(String theValue) { if (theValue == null) { return null; } URI retVal; try { retVal = new URI(theValue).normalize(); String urlString = retVal.toString(); if (urlString.endsWith("/") && urlString.length() > 1) { retVal = new URI(urlString.substring(0, urlString.length() - 1)); } } catch (URISyntaxException e) { ourLog.debug("Failed to normalize URL '{}', message was: {}", theValue, e.toString()); return theValue; } return retVal.toASCIIString(); }
98. FileOutputCommitter#getFinalPath()
View license/** * Find the final name of a given output file, given the job output directory * and the work directory. * @param jobOutputDir the job's output directory * @param taskOutput the specific task output file * @param taskOutputPath the job's work directory * @return the final path for the specific output file * @throws IOException */ private Path getFinalPath(Path jobOutputDir, Path taskOutput, Path taskOutputPath) throws IOException { URI taskOutputUri = taskOutput.toUri(); URI relativePath = taskOutputPath.toUri().relativize(taskOutputUri); if (taskOutputUri == relativePath) { throw new IOException("Can not get the relative path: base = " + taskOutputPath + " child = " + taskOutput); } if (relativePath.getPath().length() > 0) { return new Path(jobOutputDir, relativePath.getPath()); } else { return jobOutputDir; } }
99. HarFileSystem#makeQualified()
View license/* this makes a path qualified in the har filesystem * (non-Javadoc) * @see org.apache.hadoop.fs.FilterFileSystem#makeQualified( * org.apache.hadoop.fs.Path) */ @Override public Path makeQualified(Path path) { // make sure that we just get the // path component Path fsPath = path; if (!path.isAbsolute()) { fsPath = new Path(archivePath, path); } URI tmpURI = fsPath.toUri(); fsPath = new Path(tmpURI.getPath()); //change this to Har uri URI tmp = null; try { tmp = new URI(uri.getScheme(), harAuth, fsPath.toString(), tmpURI.getQuery(), tmpURI.getFragment()); } catch (URISyntaxException ue) { LOG.error("Error in URI ", ue); } if (tmp != null) { return new Path(tmp.toString()); } return null; }
100. TestValidateNamespaceDirPolicy#setUp()
View license@Before public void setUp() throws IOException, URISyntaxException { conf = new Configuration(); dir1.delete(); dir2.delete(); if (dir1.exists()) FileUtil.fullyDelete(dir1); if (dir2.exists()) FileUtil.fullyDelete(dir2); uri1 = new URI("file:" + dir1.getAbsolutePath()); uri2 = new URI("file:" + dir2.getAbsolutePath()); dirs.clear(); dirs.add(uri1); dirs.add(uri2); }