Search in sources :

Example 1 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project flow by vaadin.

the class BootstrapHandlerTest method no_body_size_or_page_configurator_still_adds_margin_for_body.

// 2344
@Test
public void no_body_size_or_page_configurator_still_adds_margin_for_body() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(RootNavigationTarget.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Elements allElements = page.head().getAllElements();
    Optional<Element> styleTag = allElements.stream().filter(element -> element.tagName().equals("style")).findFirst();
    Assert.assertTrue("Expected a style element in head.", styleTag.isPresent());
    Assert.assertTrue("The first style tag should start with body style containing margin", styleTag.get().toString().startsWith("<style type=\"text/css\">body {margin:0;}"));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) Component(com.vaadin.flow.component.Component) JavaScript(com.vaadin.flow.component.dependency.JavaScript) Inline(com.vaadin.flow.component.page.Inline) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) TargetElement(com.vaadin.flow.component.page.TargetElement) Registration(com.vaadin.flow.shared.Registration) PageTitle(com.vaadin.flow.router.PageTitle) Router(com.vaadin.flow.router.Router) Route(com.vaadin.flow.router.Route) RouteAlias(com.vaadin.flow.router.RouteAlias) Theme(com.vaadin.flow.theme.Theme) Assert.assertThat(org.junit.Assert.assertThat) Locale(java.util.Locale) Element(org.jsoup.nodes.Element) After(org.junit.After) UI(com.vaadin.flow.component.UI) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Document(org.jsoup.nodes.Document) LoadMode(com.vaadin.flow.shared.ui.LoadMode) BodySize(com.vaadin.flow.component.page.BodySize) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Elements(org.jsoup.select.Elements) ApplicationConstants(com.vaadin.flow.shared.ApplicationConstants) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Matchers(org.mockito.Matchers) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) Dependency(com.vaadin.flow.shared.ui.Dependency) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) Tag(com.vaadin.flow.component.Tag) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Before(org.junit.Before) Text(com.vaadin.flow.component.Text) RouterLayout(com.vaadin.flow.router.RouterLayout) Html(com.vaadin.flow.component.Html) StyleSheet(com.vaadin.flow.component.dependency.StyleSheet) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) Mockito(org.mockito.Mockito) Assert(org.junit.Assert) Collections(java.util.Collections) Viewport(com.vaadin.flow.component.page.Viewport) ParentLayout(com.vaadin.flow.router.ParentLayout) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) TargetElement(com.vaadin.flow.component.page.TargetElement) Element(org.jsoup.nodes.Element) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 2 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project OpenGrok by OpenGrok.

the class ProjectMessageTest method testAdd.

@Test
public void testAdd() throws Exception {
    Assert.assertTrue(env.getRepositories().isEmpty());
    Assert.assertTrue(env.getProjects().isEmpty());
    // Add a group matching the project to be added.
    String groupName = "mercurialgroup";
    Group group = new Group(groupName, "mercurial.*");
    env.getGroups().add(group);
    Assert.assertTrue(env.hasGroups());
    Assert.assertEquals(1, env.getGroups().stream().filter(g -> g.getName().equals(groupName)).collect(Collectors.toSet()).size());
    Assert.assertEquals(0, group.getRepositories().size());
    Assert.assertEquals(0, group.getProjects().size());
    // Prepare project addition.
    Message m = new ProjectMessage();
    m.setText("add");
    m.addTag("mercurial");
    // Add a sub-repository.
    String repoPath = repository.getSourceRoot() + File.separator + "mercurial";
    File mercurialRoot = new File(repoPath);
    File subDir = new File(mercurialRoot, "usr");
    Assert.assertTrue(subDir.mkdir());
    String subRepoPath = repoPath + File.separator + "usr" + File.separator + "closed";
    File mercurialSubRoot = new File(subRepoPath);
    MercurialRepositoryTest.runHgCommand(mercurialRoot, "clone", mercurialRoot.getAbsolutePath(), subRepoPath);
    // Add the project.
    env.setScanningDepth(3);
    m.apply(env);
    // Check that the project was added properly.
    Assert.assertTrue(env.getProjects().containsKey("mercurial"));
    Assert.assertEquals(1, env.getProjects().size());
    Assert.assertEquals(2, env.getRepositories().size());
    Assert.assertEquals(1, group.getRepositories().size());
    Assert.assertEquals(0, group.getProjects().size());
    Assert.assertEquals(1, group.getRepositories().stream().filter(p -> p.getName().equals("mercurial")).collect(Collectors.toSet()).size());
    // Check that HistoryGuru now includes the project in its list.
    Set<String> directoryNames = HistoryGuru.getInstance().getRepositories().stream().map(ri -> ri.getDirectoryName()).collect(Collectors.toSet());
    Assert.assertTrue("though it should contain the top root,", directoryNames.contains(repoPath) || directoryNames.contains(mercurialRoot.getCanonicalPath()));
    Assert.assertTrue("though it should contain the sub-root,", directoryNames.contains(subRepoPath) || directoryNames.contains(mercurialSubRoot.getCanonicalPath()));
    // Add more projects and check that they have been added incrementally.
    // At the same time, it checks that multiple projects can be added
    // with single message.
    m.setTags(new TreeSet<>());
    m.addTag("git");
    m.addTag("svn");
    m.apply(env);
    Assert.assertEquals(3, env.getProjects().size());
    Assert.assertEquals(4, env.getRepositories().size());
    Assert.assertTrue(env.getProjects().containsKey("git"));
    Assert.assertTrue(env.getProjects().containsKey("svn"));
    Assert.assertFalse(HistoryGuru.getInstance().getRepositories().stream().map(ri -> ri.getDirectoryName()).collect(Collectors.toSet()).contains("git"));
    Assert.assertFalse(HistoryGuru.getInstance().getRepositories().stream().map(ri -> ri.getDirectoryName()).collect(Collectors.toSet()).contains("svn"));
}
Also used : IOUtils.removeRecursive(org.opensolaris.opengrok.util.IOUtils.removeRecursive) HistoryGuru(org.opensolaris.opengrok.history.HistoryGuru) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Indexer(org.opensolaris.opengrok.index.Indexer) RepositoryInstalled(org.opensolaris.opengrok.condition.RepositoryInstalled) GitRepository(org.opensolaris.opengrok.history.GitRepository) Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) After(org.junit.After) Assume(org.junit.Assume) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Group(org.opensolaris.opengrok.configuration.Group) Before(org.junit.Before) MercurialRepository(org.opensolaris.opengrok.history.MercurialRepository) SubversionRepository(org.opensolaris.opengrok.history.SubversionRepository) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) TestRepository(org.opensolaris.opengrok.util.TestRepository) List(java.util.List) IndexDatabase(org.opensolaris.opengrok.index.IndexDatabase) RepositoryFactory(org.opensolaris.opengrok.history.RepositoryFactory) MercurialRepositoryTest(org.opensolaris.opengrok.history.MercurialRepositoryTest) Assert(org.junit.Assert) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) Group(org.opensolaris.opengrok.configuration.Group) File(java.io.File) Test(org.junit.Test) MercurialRepositoryTest(org.opensolaris.opengrok.history.MercurialRepositoryTest)

Example 3 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project keycloak by keycloak.

the class AuthorizationTest method testEnableAuthorizationServices.

@Test
public void testEnableAuthorizationServices() {
    ClientResource clientResource = getClientResource();
    ClientRepresentation resourceServer = getResourceServer();
    RealmResource realm = realmsResouce().realm(getRealmId());
    UserRepresentation serviceAccount = realm.users().search(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + resourceServer.getClientId()).get(0);
    Assert.assertNotNull(serviceAccount);
    List<RoleRepresentation> serviceAccountRoles = realm.users().get(serviceAccount.getId()).roles().clientLevel(resourceServer.getId()).listEffective();
    Assert.assertTrue(serviceAccountRoles.stream().anyMatch(roleRepresentation -> "uma_protection".equals(roleRepresentation.getName())));
    enableAuthorizationServices(false);
    enableAuthorizationServices(true);
    serviceAccount = clientResource.getServiceAccountUser();
    Assert.assertNotNull(serviceAccount);
    realm = realmsResouce().realm(getRealmId());
    serviceAccountRoles = realm.users().get(serviceAccount.getId()).roles().clientLevel(resourceServer.getId()).listEffective();
    Assert.assertTrue(serviceAccountRoles.stream().anyMatch(roleRepresentation -> "uma_protection".equals(roleRepresentation.getName())));
    JSPolicyRepresentation policy = new JSPolicyRepresentation();
    policy.setName("should be removed");
    policy.setCode("");
    clientResource.authorization().policies().js().create(policy);
    List<ResourceRepresentation> defaultResources = clientResource.authorization().resources().resources();
    assertEquals(1, defaultResources.size());
    List<PolicyRepresentation> defaultPolicies = clientResource.authorization().policies().policies();
    assertEquals(3, defaultPolicies.size());
    enableAuthorizationServices(false);
    enableAuthorizationServices(true);
    ResourceServerRepresentation settings = clientResource.authorization().getSettings();
    assertEquals(PolicyEnforcerConfig.EnforcementMode.ENFORCING.name(), settings.getPolicyEnforcementMode().name());
    assertTrue(settings.isAllowRemoteResourceManagement());
    assertEquals(resourceServer.getId(), settings.getClientId());
    defaultResources = clientResource.authorization().resources().resources();
    assertEquals(1, defaultResources.size());
    defaultPolicies = clientResource.authorization().policies().policies();
    assertEquals(2, defaultPolicies.size());
    serviceAccount = clientResource.getServiceAccountUser();
    Assert.assertNotNull(serviceAccount);
    serviceAccountRoles = realm.users().get(serviceAccount.getId()).roles().clientLevel(resourceServer.getId()).listEffective();
    Assert.assertTrue(serviceAccountRoles.stream().anyMatch(roleRepresentation -> "uma_protection".equals(roleRepresentation.getName())));
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) PolicyEnforcerConfig(org.keycloak.representations.adapters.config.PolicyEnforcerConfig) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) ServiceAccountConstants(org.keycloak.common.constants.ServiceAccountConstants) ResourceServerRepresentation(org.keycloak.representations.idm.authorization.ResourceServerRepresentation) List(java.util.List) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) Assert(org.junit.Assert) ClientResource(org.keycloak.admin.client.resource.ClientResource) RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceServerRepresentation(org.keycloak.representations.idm.authorization.ResourceServerRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 4 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project gridss by PapenfussLab.

the class SequentialEvidenceAllocatorTest method RemoteOverlap_localLookup_should_split_on_referenceIndex_and_direction.

@Test
public void RemoteOverlap_localLookup_should_split_on_referenceIndex_and_direction() {
    final ProcessingContext pc = getContext();
    pc.getVariantCallingParameters().writeFiltered = true;
    pc.getVariantCallingParameters().minScore = 0;
    pc.getVariantCallingParameters().breakendMargin = 0;
    StubSAMEvidenceSource ses = new StubSAMEvidenceSource(pc, null, 0, 0, 100);
    ses.evidence.add(SCE(FWD, Read(0, 1, "1S1M1S")));
    ses.evidence.add(SCE(BWD, Read(0, 1, "1S1M1S")));
    // ses.evidence.add(SCE(BWD, Read(1, 1, "1S1M1S")));
    // ses.evidence.add(SCE(FWD, Read(1, 1, "1S1M1S")));
    SequentialEvidenceAllocator allocator = new SequentialEvidenceAllocator(pc, ImmutableList.of((VariantContextDirectedBreakpoint) TestHelper.minimalVariant().breakpoint(new BreakpointSummary(1, FWD, 1, 1, 1, 0, FWD, 1, 1, 1), "").phredScore(1).id("call").make()).iterator(), ses.evidence.iterator(), Integer.MAX_VALUE, true);
    // shouldn't crash
    VariantEvidenceSupport ves = allocator.next();
    Assert.assertTrue(ves.support.stream().allMatch(e -> ves.variant.getBreakendSummary().overlaps(e.getBreakendSummary())));
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) VariantEvidenceSupport(au.edu.wehi.idsv.SequentialEvidenceAllocator.VariantEvidenceSupport) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) SAMRecord(htsjdk.samtools.SAMRecord) ArrayList(java.util.ArrayList) VariantEvidenceSupport(au.edu.wehi.idsv.SequentialEvidenceAllocator.VariantEvidenceSupport) Test(org.junit.Test)

Example 5 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project flink by apache.

the class FutureUtilsTest method testFutureContinuation.

private void testFutureContinuation(BiFunction<CompletableFuture<?>, Executor, CompletableFuture<?>> testFunctionGenerator) {
    CompletableFuture<?> startFuture = new CompletableFuture<>();
    final AtomicBoolean runWithExecutor = new AtomicBoolean(false);
    Executor executor = r -> {
        r.run();
        runWithExecutor.set(true);
    };
    // branch for a start future that has not completed
    CompletableFuture<?> continuationFuture = testFunctionGenerator.apply(startFuture, executor);
    Assert.assertFalse(continuationFuture.isDone());
    startFuture.complete(null);
    Assert.assertTrue(runWithExecutor.get());
    Assert.assertTrue(continuationFuture.isDone());
    // branch for a start future that was completed
    runWithExecutor.set(false);
    continuationFuture = testFunctionGenerator.apply(startFuture, executor);
    Assert.assertFalse(runWithExecutor.get());
    Assert.assertTrue(continuationFuture.isDone());
}
Also used : Matchers.arrayContaining(org.hamcrest.Matchers.arrayContaining) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) Arrays(java.util.Arrays) ScheduledFuture(java.util.concurrent.ScheduledFuture) Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) BiFunction(java.util.function.BiFunction) Assert.assertThrows(org.junit.Assert.assertThrows) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) Matchers.not(org.hamcrest.Matchers.not) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) TestLogger(org.apache.flink.util.TestLogger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) ExecutorService(java.util.concurrent.ExecutorService) TestExecutorResource(org.apache.flink.testutils.executor.TestExecutorResource) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TestingUtils(org.apache.flink.testutils.TestingUtils) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.is(org.hamcrest.Matchers.is) Assert(org.junit.Assert) Time(org.apache.flink.api.common.time.Time) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Executor(java.util.concurrent.Executor)

Aggregations

Assert (org.junit.Assert)88 Assert.assertTrue (org.junit.Assert.assertTrue)88 Test (org.junit.Test)88 Assert.assertEquals (org.junit.Assert.assertEquals)84 List (java.util.List)82 Before (org.junit.Before)67 UUID (java.util.UUID)55 Assert.assertFalse (org.junit.Assert.assertFalse)54 Autowired (org.springframework.beans.factory.annotation.Autowired)53 Assert.assertNotNull (org.junit.Assert.assertNotNull)52 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)51 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)49 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)48 Transactional (org.springframework.transaction.annotation.Transactional)46 After (org.junit.After)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)42 ApplicationContext (org.springframework.context.ApplicationContext)38 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)37 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)36