@Test public void getActiveProfiles_fromSystemProperties_withMultipleProfiles() { System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, "foo,bar"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("foo", "bar")); System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME); }
@Test public void getActiveProfiles_fromSystemProperties_withMulitpleProfiles_withWhitespace() { System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, " bar , baz "); // notice whitespace assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("bar", "baz")); System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME); }
@Test public void setActiveProfiles() { environment.setActiveProfiles("local", "embedded"); String[] activeProfiles = environment.getActiveProfiles(); assertThat(Arrays.asList(activeProfiles), hasItems("local", "embedded")); assertThat(activeProfiles.length, is(2)); }
private void assertMerge(DefaultListableBeanFactory bf) { TestBean topLevel = bf.getBean("topLevelConcreteTestBean", TestBean.class); // has the concrete child bean values assertThat((Iterable<String>) topLevel.getSomeList(), hasItems("charlie", "delta")); // but does not merge the parent values assertThat((Iterable<String>) topLevel.getSomeList(), not(hasItems("alpha", "bravo"))); TestBean firstLevel = bf.getBean("firstLevelNestedTestBean", TestBean.class); // merges all values assertThat((Iterable<String>) firstLevel.getSomeList(), hasItems("charlie", "delta", "echo", "foxtrot")); TestBean secondLevel = bf.getBean("secondLevelNestedTestBean", TestBean.class); // merges all values assertThat((Iterable<String>)secondLevel.getSomeList(), hasItems("charlie", "delta", "echo", "foxtrot", "golf", "hotel")); }
@Test public void setDefaultProfiles() { environment.setDefaultProfiles(); assertThat(environment.getDefaultProfiles().length, is(0)); environment.setDefaultProfiles("pd1"); assertThat(Arrays.asList(environment.getDefaultProfiles()), hasItem("pd1")); environment.setDefaultProfiles("pd2", "pd3"); assertThat(Arrays.asList(environment.getDefaultProfiles()), not(hasItem("pd1"))); assertThat(Arrays.asList(environment.getDefaultProfiles()), hasItems("pd2", "pd3")); }
@Test public void addActiveProfile() { assertThat(environment.getActiveProfiles().length, is(0)); environment.setActiveProfiles("local", "embedded"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("local", "embedded")); assertThat(environment.getActiveProfiles().length, is(2)); environment.addActiveProfile("p1"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("p1")); assertThat(environment.getActiveProfiles().length, is(3)); environment.addActiveProfile("p2"); environment.addActiveProfile("p3"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("p2", "p3")); assertThat(environment.getActiveProfiles().length, is(5)); }
@Test @Annotated public void testGetMethodsListWithAnnotation() throws NoSuchMethodException { assertEquals(0, MethodUtils.getMethodsListWithAnnotation(Object.class, Annotated.class).size()); final List<Method> methodWithAnnotation = MethodUtils.getMethodsListWithAnnotation(MethodUtilsTest.class, Annotated.class); assertEquals(2, methodWithAnnotation.size()); assertThat(methodWithAnnotation, hasItems( MethodUtilsTest.class.getMethod("testGetMethodsWithAnnotation"), MethodUtilsTest.class.getMethod("testGetMethodsListWithAnnotation") )); }
@Test public void shouldWorkForClassLoaderWithNoParent() throws Exception { // Given ClassLoader loader = new URLClassLoader( urls( "file:///file1", "file:///file2" ), null ); // When Set<String> elements = fullClasspathFor( loader ); // Then assertThat( elements, hasItems( pathTo( "file1" ), pathTo( "file2" ) ) ); }
@Test public void shouldWorkForClassLoaderWithSingleParent() throws Exception { // Given ClassLoader parent = new URLClassLoader( urls( "file:///file1", "file:///file2" ), null ); ClassLoader child = new URLClassLoader( urls( "file:///file3" ), parent ); // When Set<String> elements = fullClasspathFor( child ); // Then assertThat( elements, hasItems( pathTo( "file1" ), pathTo( "file2" ), pathTo( "file3" ) ) ); }
@Test public void shouldWorkForClassLoaderHierarchy() throws Exception { // Given ClassLoader loader1 = new URLClassLoader( urls( "file:///file1" ), null ); ClassLoader loader2 = new URLClassLoader( urls( "file:///file2" ), loader1 ); ClassLoader loader3 = new URLClassLoader( urls( "file:///file3" ), loader2 ); ClassLoader loader4 = new URLClassLoader( urls( "file:///file4" ), loader3 ); // When Set<String> elements = fullClasspathFor( loader4 ); // Then assertThat( elements, hasItems( pathTo( "file1" ), pathTo( "file2" ), pathTo( "file3" ), pathTo( "file4" ) ) ); }
@Test public void shouldGetOnlyPlainTextVariables() throws CryptoException { EnvironmentVariablesConfig environmentVariablesConfig = new EnvironmentVariablesConfig(); EnvironmentVariableConfig plainVar1 = new EnvironmentVariableConfig("var1", "var1_value"); EnvironmentVariableConfig plainVar2 = new EnvironmentVariableConfig("var2", "var2_value"); EnvironmentVariableConfig var1 = secureVariable(goCipher, "foo1", "bar1", "encryptedBar1"); EnvironmentVariableConfig var2 = secureVariable(goCipher, "foo2", "bar2", "encryptedBar2"); environmentVariablesConfig.addAll(Arrays.asList(var1, var2, plainVar1, plainVar2)); List<EnvironmentVariableConfig> variables = environmentVariablesConfig.getPlainTextVariables(); assertThat(variables.size(), is(2)); assertThat(variables, hasItems(plainVar1, plainVar2)); }
@Test public void shouldGetExtensionNamesOfAllExtensionsContainedWithin() throws Exception { CombinedPluginInfo pluginInfo = new CombinedPluginInfo(asList( new PluggableTaskPluginInfo(null, null, null), new NotificationPluginInfo(null, null))); assertThat(pluginInfo.extensionNames().size(), is(2)); assertThat(pluginInfo.extensionNames(), hasItems(NOTIFICATION_EXTENSION, PLUGGABLE_TASK_EXTENSION)); }
@Test public void shouldGetPluggableSCMMaterialConfigs() throws Exception { SvnMaterialConfig svn = new SvnMaterialConfig("svn", false); PluggableSCMMaterialConfig pluggableSCMMaterialOne = new PluggableSCMMaterialConfig("scm-id-1"); PluggableSCMMaterialConfig pluggableSCMMaterialTwo = new PluggableSCMMaterialConfig("scm-id-2"); PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(svn, pluggableSCMMaterialOne, pluggableSCMMaterialTwo)); List<PluggableSCMMaterialConfig> pluggableSCMMaterialConfigs = pipelineConfig.pluggableSCMMaterialConfigs(); assertThat(pluggableSCMMaterialConfigs.size(), is(2)); assertThat(pluggableSCMMaterialConfigs, hasItems(pluggableSCMMaterialOne, pluggableSCMMaterialTwo)); }
@Test public void shouldListAllLoadedPlugins() throws Exception { GoPluginDescriptor descriptor1 = GoPluginDescriptor.usingId("id1", null, null, true); registry.loadPlugin(descriptor1); GoPluginDescriptor descriptor2 = GoPluginDescriptor.usingId("id2", null, null, true); registry.loadPlugin(descriptor2); assertThat(registry.plugins().size(), is(2)); assertThat(registry.plugins(), hasItems(descriptor1, descriptor2)); }
@Test public void shouldGetPackageMaterialConfigs() throws Exception { SvnMaterialConfig svn = new SvnMaterialConfig("svn", false); PackageMaterialConfig packageMaterialOne = new PackageMaterialConfig(); PackageMaterialConfig packageMaterialTwo = new PackageMaterialConfig(); PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(svn, packageMaterialOne, packageMaterialTwo)); List<PackageMaterialConfig> packageMaterialConfigs = pipelineConfig.packageMaterialConfigs(); assertThat(packageMaterialConfigs.size(), is(2)); assertThat(packageMaterialConfigs, hasItems(packageMaterialOne, packageMaterialTwo)); }
void shouldNotifyInStreamWithDetail( String version, String query, InputPosition pos, NotificationCode code, NotificationDetail detail ) { //when Result result = db().execute( version + query ); //then NotificationCode.Notification notification = code.notification( pos, detail ); assertThat( Iterables.asList( result.getNotifications() ), Matchers.hasItems( notification ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
void shouldNotifyInStream( String version, String query, InputPosition pos, NotificationCode code ) { //when Result result = db().execute( version + query ); //then NotificationCode.Notification notification = code.notification( pos ); assertThat( Iterables.asList( result.getNotifications() ), Matchers.hasItems( notification ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
@Test public void shouldRecordMultipleUserAgents() throws IOException, ServletException { filter.doFilter( request( "agent1" ), null, filterChain ); filter.doFilter( request( "agent2" ), null, filterChain ); assertThat( agents.recentItems(), hasItems( "agent1", "agent2" ) ); }
@Test public void shouldRemoveGivenPackageFromTheRepository() throws Exception { PackageDefinition packageDefinitionOne = new PackageDefinition("pid1", "pname1", null); PackageDefinition packageDefinitionTwo = new PackageDefinition("pid2", "pname2", null); PackageRepository packageRepository = new PackageRepository(); packageRepository.addPackage(packageDefinitionOne); packageRepository.addPackage(packageDefinitionTwo); packageRepository.removePackage("pid1"); assertThat(packageRepository.getPackages().size(), is(1)); assertThat(packageRepository.getPackages(), hasItems(packageDefinitionTwo)); }
@Test public void shouldSetViewPermissionByDefaultIfNameIsPresentAndPermissionsAreOff_whileSettingAttributes() { PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1")); group.setConfigAttributes(m(BasicPipelineConfigs.AUTHORIZATION, a( m(Authorization.NAME, "user1", Authorization.TYPE, USER.toString(), Authorization.PRIVILEGES, privileges(OFF, OFF, OFF)), m(Authorization.NAME, "role1", Authorization.TYPE, ROLE.toString(), Authorization.PRIVILEGES, privileges(OFF, OFF, OFF))))); Authorization authorization = group.getAuthorization(); assertThat(authorization.getViewConfig().size(), is(2)); assertThat(authorization.getViewConfig(), hasItems(new AdminRole(new CaseInsensitiveString("role1")), new AdminUser(new CaseInsensitiveString("user1")))); assertThat(authorization.getOperationConfig().size(), is(0)); assertThat(authorization.getAdminsConfig().size(), is(0)); }