private void assertThatFiltersMatchExpectedAutoConfigList(String url) { Iterator<Filter> filters = getFilters(url).iterator(); assertThat(filters.next()).isInstanceOf(SecurityContextPersistenceFilter.class); assertThat(filters.next()).isInstanceOf(WebAsyncManagerIntegrationFilter.class); assertThat(filters.next()).isInstanceOf(HeaderWriterFilter.class); assertThat(filters.next()).isInstanceOf(CsrfFilter.class); assertThat(filters.next()).isInstanceOf(LogoutFilter.class); assertThat(filters.next()).isInstanceOf(UsernamePasswordAuthenticationFilter.class); assertThat(filters.next()).isInstanceOf(DefaultLoginPageGeneratingFilter.class); assertThat(filters.next()).isInstanceOf(DefaultLogoutPageGeneratingFilter.class); assertThat(filters.next()).isInstanceOf(BasicAuthenticationFilter.class); assertThat(filters.next()).isInstanceOf(RequestCacheAwareFilter.class); assertThat(filters.next()).isInstanceOf(SecurityContextHolderAwareRequestFilter.class); assertThat(filters.next()).isInstanceOf(AnonymousAuthenticationFilter.class); assertThat(filters.next()).isInstanceOf(SessionManagementFilter.class); assertThat(filters.next()).isInstanceOf(ExceptionTranslationFilter.class); assertThat(filters.next()).isInstanceOf(FilterSecurityInterceptor.class) .hasFieldOrPropertyWithValue("observeOncePerRequest", true); }
@Test public void shouldParseQuietFlag() throws Exception { final Optional<ExitCode> parse = commandLine .parse("-q", "--help"); assertThat(parse) .isEmpty(); assertThat(commandLine.getMainCommand().getVerboseOptions()) .isNotNull() .hasFieldOrPropertyWithValue("verbose", false) .hasFieldOrPropertyWithValue("quiet", true); final ExitCode exitCode = commandLine.run(); assertThat(exitCode) .isEqualTo(NO_ERROR); }
@Test public void shouldParseVerboseFlag() throws Exception { final Optional<ExitCode> parse = commandLine .parse("-v", "--help"); assertThat(parse) .isEmpty(); assertThat(commandLine.getMainCommand().getVerboseOptions()) .isNotNull() .hasFieldOrPropertyWithValue("verbose", true) .hasFieldOrPropertyWithValue("quiet", false); final ExitCode exitCode = commandLine.run(); assertThat(exitCode) .isEqualTo(NO_ERROR); }
@Test public void authenticateWhenConverterReturnsAuthenticationThenProviderPropagatesIt() { BearerTokenAuthenticationToken token = this.authentication(); Object details = mock(Object.class); token.setDetails(details); Jwt jwt = this.jwt(Collections.singletonMap("some", "value")); JwtAuthenticationToken authentication = new JwtAuthenticationToken(jwt); when(this.jwtDecoder.decode(token.getToken())).thenReturn(jwt); when(this.jwtAuthenticationConverter.convert(jwt)).thenReturn(authentication); assertThat(this.provider.authenticate(token)) .isEqualTo(authentication) .hasFieldOrPropertyWithValue("details", details); }
@Test public void shouldLoadPluginExtensions() throws Exception { final Path pluginFolder = folder.newFolder().toPath(); add(pluginFolder, "plugin.jar", "plugin.jar"); add(pluginFolder, "dummy-plugin.yml", "allure-plugin.yml"); final Optional<Plugin> loaded = pluginLoader.loadPlugin(getClass().getClassLoader(), pluginFolder); assertThat(loaded) .isPresent(); final Plugin plugin = loaded.get(); assertThat(plugin.getConfig()) .isNotNull() .hasFieldOrPropertyWithValue("id", "packages") .hasFieldOrPropertyWithValue("name", "Packages aggregator") .hasFieldOrPropertyWithValue("description", "The aggregator adds packages tab to the report"); assertThat(plugin.getExtensions()) .isNotNull() .hasSize(1); final Extension extension = plugin.getExtensions().get(0); assertThat(extension) .isNotNull() .isInstanceOf(Aggregator.class); assertThat(extension.getClass().getCanonicalName()) .isEqualTo("io.qameta.allure.packages.PackagesPlugin"); }
@Test public void shouldLoadJarsInLibDirectory() throws Exception { final Path pluginFolder = folder.newFolder().toPath(); add(pluginFolder, "plugin.jar", "lib/plugin.jar"); add(pluginFolder, "dummy-plugin.yml", "allure-plugin.yml"); final Optional<Plugin> loaded = pluginLoader.loadPlugin(getClass().getClassLoader(), pluginFolder); assertThat(loaded) .isPresent(); final Plugin plugin = loaded.get(); assertThat(plugin.getConfig()) .isNotNull() .hasFieldOrPropertyWithValue("id", "packages") .hasFieldOrPropertyWithValue("name", "Packages aggregator") .hasFieldOrPropertyWithValue("description", "The aggregator adds packages tab to the report"); assertThat(plugin.getExtensions()) .isNotNull() .hasSize(1); final Extension extension = plugin.getExtensions().get(0); assertThat(extension) .isNotNull() .isInstanceOf(Aggregator.class); assertThat(extension.getClass().getCanonicalName()) .isEqualTo("io.qameta.allure.packages.PackagesPlugin"); }
@Test public void shouldLoadStaticOnlyPlugin() throws Exception { final Path pluginFolder = folder.newFolder().toPath(); add(pluginFolder, "static-file.txt", "static/some-file"); add(pluginFolder, "dummy-plugin2.yml", "allure-plugin.yml"); final Optional<Plugin> loaded = pluginLoader.loadPlugin(getClass().getClassLoader(), pluginFolder); assertThat(loaded) .isPresent(); final Plugin plugin = loaded.get(); assertThat(plugin.getConfig()) .isNotNull() .hasFieldOrPropertyWithValue("id", "dummy"); assertThat(plugin.getExtensions()) .isNotNull() .isEmpty(); final Path unpack = folder.newFolder().toPath(); plugin.unpackReportStatic(unpack); assertThat(unpack.resolve("some-file")) .isRegularFile() .hasContent("ho-ho-ho"); }
@Test public void shouldFindLatestExecutor() throws Exception { final Configuration configuration = mock(Configuration.class); final Map<String, Object> extra1 = new HashMap<>(); final List<HistoryTrendItem> history1 = randomHistoryTrendItems(); extra1.put(HISTORY_TREND_BLOCK_NAME, history1); extra1.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(1L)); final Map<String, Object> extra2 = new HashMap<>(); final List<HistoryTrendItem> history2 = randomHistoryTrendItems(); extra2.put(HISTORY_TREND_BLOCK_NAME, history2); extra2.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(7L)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra1, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra2, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(launchResults); assertThat(data) .hasSize(1 + history1.size() + history2.size()); final HistoryTrendItem historyTrendItem = data.get(0); assertThat(historyTrendItem) .hasFieldOrPropertyWithValue("buildOrder", 7L); }
@Test public void testUpdatedProperty() { Map<String, ConfigurationProperty> left = new HashMap<>(); Map<String, ConfigurationProperty> right = new HashMap<>(); left.put("property", new ConfigurationProperty.Builder().javaType("string").build()); right.put("property", new ConfigurationProperty.Builder().javaType("STRING").build()); List<LeveledMessage> messages = new DummyHandler().computePropertiesDiffMessages(LeveledMessage.Builder::new, left, right); assertThat(messages).hasSize(1); assertThat(messages.get(0)).hasFieldOrPropertyWithValue("level", LeveledMessage.Level.INFO); assertThat(messages.get(0)).hasFieldOrPropertyWithValue("code", LeveledMessage.Code.SYNDESIS001); }
@Test public void testMissingMandatoryProperty() { Map<String, ConfigurationProperty> left = new HashMap<>(); Map<String, String> right = new HashMap<>(); left.put("property1", new ConfigurationProperty.Builder().javaType("string").build()); left.put("property2", new ConfigurationProperty.Builder().javaType("string").required(true).build()); right.put("property1", "value1"); List<LeveledMessage> messages = new DummyHandler().computeMissingMandatoryPropertiesMessages(LeveledMessage.Builder::new, left, right); assertThat(messages).hasSize(1); assertThat(messages.get(0)).hasFieldOrPropertyWithValue("level", LeveledMessage.Level.WARN); assertThat(messages.get(0)).hasFieldOrPropertyWithValue("code", LeveledMessage.Code.SYNDESIS006); }
@Test public void shouldBeAbleToSetAndUpdateAndGetState() { final StateView setStateView = new StateView(ImmutableMap.of("key1", "value1", "key2", "value2")); client.setState(setStateView); final StateView updateStateView = new StateView(ImmutableMap.of("key2", "value4", "key3", "value3")); client.updateState(updateStateView); StateView resultStateView = client.getState(); assertThat(resultStateView) .as("get returns the state which have just been updated.") .isNotNull() .hasFieldOrPropertyWithValue("state", ImmutableMap.of("key1", "value1", "key2", "value4", "key3", "value3")); }
@Test public void testRequestParameterValuesMap() { HashMap<String, String[]> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestParameterValuesMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestParameterValuesMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestParameterValuesMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testHeaderMap() { HashMap<String, String> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.headerMap()).thenReturn(map); Object bean = new Object() { @Autowired @HeaderMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).headerMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestParameterMap() { HashMap<String, String> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestParameterMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestParameterMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestParameterMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testApplicationMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.applicationMap()).thenReturn(map); Object bean = new Object() { @Autowired @ApplicationMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).applicationMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testHeaderValuesMap() { HashMap<String, String[]> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.headerValuesMap()).thenReturn(map); Object bean = new Object() { @Autowired @HeaderValuesMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).headerValuesMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestCookieMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestCookieMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestCookieMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestCookieMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
private void assertLogEvent(List<LogEvent> events, int index, Level level, String message) { assertThat(events).element(index) .hasFieldOrPropertyWithValue("level", level) .extracting("message") .extractingResultOf("getFormattedMessage") .have(new Condition<>(o -> ((String) o).contains(message), "check message")); }
private void assertLogEvent(List<LogEvent> events, int index, Level level, String message1, String message2) { assertThat(events).element(index) .hasFieldOrPropertyWithValue("level", level) .extracting("message") .extractingResultOf("getFormattedMessage") .have(new Condition<>(o -> ((String) o).contains(message1), "check message1")) .have(new Condition<>(o -> ((String) o).contains(message2), "check message2"));; }