private String loadSource() { if (source != null) { return source; } if (path.contains(CLASSPATH_PREFIX)) { return loadClasspathResource(); } return loadFileSystemResource(); }
@PluginBuilderFactory public static IndexTemplate.Builder newBuilder() { return new IndexTemplate.Builder(); }
@Test public void startsWhenSetupCorrectlyWithNameAndSource() { // given IndexTemplate.Builder builder = createTestIndexTemplateBuilder(); builder.withName(TEST_INDEX_TEMPLATE) .withPath(null) .withSource(TEST_SOURCE); // when IndexTemplate indexTemplate = builder.build(); // then Assert.assertNotNull(indexTemplate); Assert.assertNotNull(indexTemplate.getName()); Assert.assertNotNull(indexTemplate.getSource()); }
@Test public void startsWhenSetupCorrectlyWithNameAndPath() { // given IndexTemplate.Builder builder = createTestIndexTemplateBuilder(); builder.withName(TEST_INDEX_TEMPLATE) .withPath(TEST_PATH); // when IndexTemplate indexTemplate = builder.build(); // then Assert.assertNotNull(indexTemplate); Assert.assertNotNull(indexTemplate.getName()); Assert.assertNotNull(indexTemplate.getSource()); }
@PluginBuilderFactory public static IndexTemplate.Builder newBuilder() { return new IndexTemplate.Builder(); }
@Override public IndexTemplate build() { if (name == null) { throw new ConfigurationException("No name provided for IndexTemplate"); } if ((path == null && source == null) || (path != null && source != null)) { throw new ConfigurationException("Either path or source have to be provided for IndexTemplate"); } return new IndexTemplate(name, loadSource()); }
@Override public IndexTemplate build() { if (name == null) { throw new ConfigurationException("No name provided for IndexTemplate"); } if ((path == null && source == null) || (path != null && source != null)) { throw new ConfigurationException("Either path or source have to be provided for IndexTemplate"); } return new IndexTemplate(name, loadSource()); }
@Test(expected = ConfigurationException.class) public void builderThrowsExceptionWhenBothPathAndSourceAreSet() { // given IndexTemplate.Builder builder = createTestIndexTemplateBuilder(); builder.withPath(TEST_PATH) .withSource(TEST_SOURCE); // when builder.build(); }
@Test(expected = ConfigurationException.class) public void builderThrowsExceptionWhenNeitherPathOrSourceIsSet() { // given IndexTemplate.Builder builder = createTestIndexTemplateBuilder(); builder.withPath(null) .withSource(null); // when builder.build(); }
private String loadSource() { if (source != null) { return source; } if (path.contains(CLASSPATH_PREFIX)) { return loadClasspathResource(); } return loadFileSystemResource(); }