@Test public void thereShouldBeNoDuplicateNames() { final Map<String, Long> namesWithCount = StreamSupport.stream(deployment.spliterator(), true) .filter(data -> "connector".equals(data.get("kind").asText())) .flatMap(connector -> StreamSupport.stream(connector.get("data").get("actions").spliterator(), true)) .map(action -> action.get("name").asText()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); final Map<String, Long> multipleNames = namesWithCount.entrySet().stream().filter(e -> e.getValue() > 1) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); assertThat(multipleNames).as("Expected unique action names").isEmpty(); }
@Test public void thereShouldBeNoDuplicateMavenCoordinates() { final Map<String, Long> coordinatesWithCount = StreamSupport.stream(deployment.spliterator(), true) .filter(data -> "connector".equals(data.get("kind").asText())) .flatMap(connector -> StreamSupport.stream(connector.get("data").get("actions").spliterator(), true)) .filter(action -> action.get("descriptor").get("camelConnectorGAV") != null) .map(action -> action.get("descriptor").get("camelConnectorGAV").asText()) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); final Map<String, Long> multipleCoordinates = coordinatesWithCount.entrySet().stream() .filter(e -> e.getValue() > 1) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); assertThat(multipleCoordinates).as("Expected connector GAV coordinates to be unique").isEmpty(); }
public void compare(File configFolder, File destinationFolder) throws Exception { final Map<String, File> expectedFiles = flattenFolderFiles(configFolder); final Map<String, File> files = flattenFolderFiles(destinationFolder); assertThat(files).as("should have same size").hasSize(expectedFiles.size()); assertThat(expectedFiles.keySet()).as("should have same file names").isEqualTo(files.keySet()); for (String name : expectedFiles.keySet()) { compareFileContent(expectedFiles.get(name), files.get(name)); } }
@Test public void transformParameter_norwegianStemmer() { TokenFilterDef annotation = annotation( TokenFilterDef.class, NorwegianLightStemFilterFactory.class ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getType() ).as( "type" ).isEqualTo( "stemmer" ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "name", new JsonPrimitive( "light_norwegian" ) ); }
@Test public void transformParameter_tokenizerClass() { TokenFilterDef annotation = annotation( TokenFilterDef.class, SynonymFilterFactory.class, param( "tokenizerFactory", WhitespaceTokenizerFactory.class.getName() ) ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "tokenizer", new JsonPrimitive( "whitespace" ) ); }
private static void assertDelete(DeleteLuceneWork work, DeleteLuceneWork copy) { assertThat( work.getEntityType() ).as( "Delete.getEntityClass is not copied" ) .isEqualTo( copy.getEntityType() ); assertThat( work.getId() ).as( "Delete.getId is not copied" ).isEqualTo( copy.getId() ); assertThat( (Object) work.getDocument() ).as( "Delete.getDocument is not the same" ) .isEqualTo( copy.getDocument() ); assertThat( work.getIdInString() ).as( "Delete.getIdInString is not the same" ) .isEqualTo( copy.getIdInString() ); assertThat( work.getFieldToAnalyzerMap() ).as( "Delete.getFieldToAnalyzerMap is not the same" ) .isEqualTo( copy.getFieldToAnalyzerMap() ); }
@Test public void transformParameter_norwegianStemmer_bokmal() { TokenFilterDef annotation = annotation( TokenFilterDef.class, NorwegianLightStemFilterFactory.class, param( "variant", "nb" ) ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getType() ).as( "type" ).isEqualTo( "stemmer" ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "name", new JsonPrimitive( "light_norwegian" ) ); }
@Test public void transformParameter_norwegianStemmer_nynorsk() { TokenFilterDef annotation = annotation( TokenFilterDef.class, NorwegianLightStemFilterFactory.class, param( "variant", "nn" ) ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getType() ).as( "type" ).isEqualTo( "stemmer" ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "name", new JsonPrimitive( "light_nynorsk" ) ); }
@Test public void transformParameter_patternReplace() { TokenFilterDef annotation = annotation( TokenFilterDef.class, PatternReplaceFilterFactory.class, param( "replace", "first" ) ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "all", new JsonPrimitive( "false" ) ); }
@Test public void renameParameter() { TokenizerDef annotation = annotation( TokenizerDef.class, StandardTokenizerFactory.class, param( "maxTokenLength", "5" ) ); TokenizerDefinition definition = translator.translate( annotation ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "max_token_length", new JsonPrimitive( "5" ) ); assertThat( definition.getParameters().keySet() ).as( "parameter names" ) .doesNotContain( "maxTokenLength" ); }
private static void assertAdd(AddLuceneWork work, AddLuceneWork copy) { assertThat( copy.getEntityType() ).as( "Add.getEntityClass is not copied" ).isEqualTo( work.getEntityType() ); assertThat( copy.getId() ).as( "Add.getId is not copied" ).isEqualTo( work.getId() ); assertThat( copy.getIdInString() ).as( "Add.getIdInString is not the same" ).isEqualTo( work.getIdInString() ); assertThat( copy.getFieldToAnalyzerMap() ).as( "Add.getFieldToAnalyzerMap is not the same" ) .isEqualTo( work.getFieldToAnalyzerMap() ); assertDocument( work.getDocument(), copy.getDocument() ); }
private static void assertUpdate(UpdateLuceneWork work, UpdateLuceneWork copy) { assertThat( copy.getEntityType() ).as( "Add.getEntityClass is not copied" ).isEqualTo( work.getEntityType() ); assertThat( copy.getId() ).as( "Add.getId is not copied" ).isEqualTo( work.getId() ); assertThat( copy.getIdInString() ).as( "Add.getIdInString is not the same" ).isEqualTo( work.getIdInString() ); assertThat( copy.getFieldToAnalyzerMap() ).as( "Add.getFieldToAnalyzerMap is not the same" ) .isEqualTo( work.getFieldToAnalyzerMap() ); assertDocument( work.getDocument(), copy.getDocument() ); }
@Test public void passThrough_stringWithoutQuotes() { TokenFilterDef annotation = annotation( TokenFilterDef.class, ElasticsearchTokenFilterFactory.class, param( "type", "stringWithoutQuotes" ), param( "param", "stringWithoutQuotes" ) ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getType() ).as( "type" ).isEqualTo( "stringWithoutQuotes" ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "param", new JsonPrimitive( "stringWithoutQuotes" ) ); assertThat( definition.getParameters().keySet() ).as( "parameters" ) .doesNotContain( "type" ); }
@Test public void shouldBeAbleToSetAndDeleteState() { final StateView setStateView = new StateView(ImmutableMap.of("key1", "value1", "key2", "value2")); client.setState(setStateView); client.deleteState(); StateView resultStateView = client.getState(); assertThat(resultStateView.getState()) .as("get returns an empty state after delete.") .isNotNull().isEmpty(); }
@Test public void transformParameter() { CharFilterDef annotation = annotation( CharFilterDef.class, HTMLStripCharFilterFactory.class, param( "escapedTags", "foo,bar" ) ); CharFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "escaped_tags", JsonBuilder.array().add( new JsonPrimitive( "foo" ) ).add( new JsonPrimitive( "bar" ) ).build() ); }
@Test public void transformParameter_singleElementArray() { TokenFilterDef annotation = annotation( TokenFilterDef.class, PatternCaptureGroupFilterFactory.class, param( "pattern", "foo" ) ); TokenFilterDefinition definition = translator.translate( annotation ); assertThat( definition.getParameters() ).as( "parameters" ) .containsEntry( "patterns", JsonBuilder.array().add( new JsonPrimitive( "foo" ) ).build() ); }
@Test public void should_create_page_with_default_content_type() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME).setDisplayName(DISPLAY_NAME).setDescription(DESCRIPTION); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(fields).as("should set content type").containsOnly(entry(PageField.NAME, NAME), entry(PageField.DISPLAY_NAME, DISPLAY_NAME), entry(PageField.DESCRIPTION, DESCRIPTION), entry(PageField.CONTENT_TYPE, ContentType.PAGE), entry(PageField.CONTENT_NAME, ZIP_FILE_NAME) ); assertThat(pageCreator.getName()).isEqualTo(NAME); }
@Test public void should_create_page_with_form_content_type() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME, ContentType.FORM, 12345L).setDisplayName(DISPLAY_NAME); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(fields).as("should set content type").containsOnly( entry(PageField.NAME, NAME), entry(PageField.DISPLAY_NAME, DISPLAY_NAME), entry(PageField.CONTENT_TYPE, ContentType.FORM), entry(PageField.PROCESS_DEFINITION_ID, 12345L), entry(PageField.CONTENT_NAME, ZIP_FILE_NAME) ); }
@Test public void should_create_page_with_process_definition() { // given final PageCreator pageCreator = new PageCreator(NAME, ZIP_FILE_NAME).setDisplayName(DISPLAY_NAME).setDescription(DESCRIPTION) .setProcessDefinitionId(PROCESS_DEFINITION_ID).setContentType(ContentType.FORM); // when final Map<PageField, Serializable> fields = pageCreator.getFields(); // then assertThat(fields).as("should set content type").containsOnly(entry(PageField.NAME, NAME), entry(PageField.DISPLAY_NAME, DISPLAY_NAME), entry(PageField.DESCRIPTION, DESCRIPTION), entry(PageField.CONTENT_TYPE, ContentType.PAGE), entry(PageField.CONTENT_NAME, ZIP_FILE_NAME), entry(PageField.CONTENT_TYPE, ContentType.FORM), entry(PageField.PROCESS_DEFINITION_ID, PROCESS_DEFINITION_ID) ); assertThat(pageCreator.getName()).isEqualTo(NAME); }
@Test public void should_create_page_with_default_fields() { // given final PageUpdater pageUpdater = new PageUpdater().setName(NAME).setContentName(ZIP_FILE_NAME).setDisplayName(DISPLAY_NAME).setDescription(DESCRIPTION) .setContentType(ContentType.FORM).setProcessDefinitionId(PROCESS_DEFINITION_ID); // when final Map<PageUpdater.PageUpdateField, Serializable> fields = pageUpdater.getFields(); // then assertThat(fields).as("should set content type").containsOnly(entry(PageUpdater.PageUpdateField.NAME, NAME), entry(PageUpdater.PageUpdateField.DISPLAY_NAME, DISPLAY_NAME), entry(PageUpdater.PageUpdateField.DESCRIPTION, DESCRIPTION), entry(PageUpdater.PageUpdateField.CONTENT_TYPE, ContentType.FORM), entry(PageUpdater.PageUpdateField.CONTENT_NAME, ZIP_FILE_NAME), entry(PageUpdater.PageUpdateField.PROCESS_DEFINITION_ID, PROCESS_DEFINITION_ID), entry(PageUpdater.PageUpdateField.NAME, NAME) ); }