org.springframework.test.annotation.IfProfileValue Java Examples

The following examples show how to use org.springframework.test.annotation.IfProfileValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProfileValueChecker.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Determine if the test specified by arguments to the
 * {@linkplain #ProfileValueChecker constructor} is <em>enabled</em> in
 * the current environment, as configured via the {@link IfProfileValue
 * &#064;IfProfileValue} annotation.
 * <p>If the test is not annotated with {@code @IfProfileValue} it is
 * considered enabled.
 * <p>If a test is not enabled, this method will abort further evaluation
 * of the execution chain with a failed assumption; otherwise, this method
 * will simply evaluate the next {@link Statement} in the execution chain.
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class)
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class)
 * @throws AssumptionViolatedException if the test is disabled
 * @throws Throwable if evaluation of the next statement fails
 */
@Override
public void evaluate() throws Throwable {
	if (this.testMethod == null) {
		if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testClass)) {
			Annotation ann = AnnotatedElementUtils.findMergedAnnotation(this.testClass, IfProfileValue.class);
			throw new AssumptionViolatedException(String.format(
					"Profile configured via [%s] is not enabled in this environment for test class [%s].",
					ann, this.testClass.getName()));
		}
	}
	else {
		if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testMethod, this.testClass)) {
			throw new AssumptionViolatedException(String.format(
					"Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].",
					this.testMethod));
		}
	}

	this.next.evaluate();
}
 
Example #2
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testInsertSnowFlakeCache.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testInsertSnowFlakeCache.result.xml")
public void testInsertSnowFlakeCache() {
	Account_ account = new Account_();
	account.setName("ann");
	accountService.insert(account);

	int i = accountService.count(new Account_());
	Assert.assertEquals(1, i);

	Account_ account2 = new Account_();
	account2.setName("bob");
	accountService.insertSnowFlake(account2);

	int i2 = accountService.count(new Account_());
	Assert.assertEquals(2, i2);
}
 
Example #3
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 6 votes vote down vote up
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect() {
	Role_ r = new Role_();
	r.setId(1);
	r.setName("ann");
	roleService.insert(r);
	Account_ a = new Account_();
	a.setId(1L);
	a.setRole(r);
	a.setEmail("email");
	accountService.insert(a);

	Account_ account = accountService.select(1);
	Assert.assertEquals("ann", account.getRole().getName());

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 1);
	m.put("name", "bob");
	roleService.updateDirect(m);

	Account_ account2 = accountService.select(1);
	Assert.assertEquals("ann", account2.getRole().getName());
}
 
Example #4
Source File: JpaLockingStrategyTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
/**
 * Test concurrent acquire/release semantics for existing lock.
 */
@Test
@IfProfileValue(name="cas.jpa.concurrent", value="true")
public void testConcurrentAcquireAndReleaseOnExistingLock() throws Exception {
    final LockingStrategy[] locks = getConcurrentLocks("concurrent-exists");
    locks[0].acquire();
    locks[0].release();
    final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE);
    try {
        testConcurrency(executor, locks);
    } catch (final Exception e) {
        logger.debug("testConcurrentAcquireAndReleaseOnExistingLock produced an error", e);
        fail("testConcurrentAcquireAndReleaseOnExistingLock failed.");
    } finally {
        executor.shutdownNow();
    }
}
 
Example #5
Source File: JpaTicketRegistryTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
@Test
@IfProfileValue(name="cas.jpa.concurrent", value="true")
public void testConcurrentServiceTicketGeneration() throws Exception {
    final TicketGrantingTicket newTgt = newTGT();
    addTicketInTransaction(newTgt);
    final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE);
    try {
        final List<ServiceTicketGenerator> generators = new ArrayList<ServiceTicketGenerator>(CONCURRENT_SIZE);
        for (int i = 0; i < CONCURRENT_SIZE; i++) {
            generators.add(new ServiceTicketGenerator(newTgt.getId()));
        }
        final List<Future<String>> results = executor.invokeAll(generators);
        for (Future<String> result : results) {
            assertNotNull(result.get());
        }
    } catch (final Exception e) {
        logger.debug("testConcurrentServiceTicketGeneration produced an error", e);
        fail("testConcurrentServiceTicketGeneration failed.");
    } finally {
        executor.shutdownNow();
    }
}
 
Example #6
Source File: JpaLockingStrategyTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Test concurrent acquire/release semantics for existing lock.
 */
@Test
@IfProfileValue(name="cas.jpa.concurrent", value="true")
public void verifyConcurrentAcquireAndReleaseOnExistingLock() throws Exception {
    final LockingStrategy[] locks = getConcurrentLocks("concurrent-exists");
    locks[0].acquire();
    locks[0].release();
    final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE);
    try {
        testConcurrency(executor, locks);
    } catch (final Exception e) {
        logger.debug("testConcurrentAcquireAndReleaseOnExistingLock produced an error", e);
        fail("testConcurrentAcquireAndReleaseOnExistingLock failed.");
    } finally {
        executor.shutdownNow();
    }
}
 
Example #7
Source File: JpaTicketRegistryTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
@IfProfileValue(name="cas.jpa.concurrent", value="true")
public void verifyConcurrentServiceTicketGeneration() throws Exception {
    final TicketGrantingTicket newTgt = newTGT();
    addTicketInTransaction(newTgt);
    final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE);
    try {
        final List<ServiceTicketGenerator> generators = new ArrayList<>(CONCURRENT_SIZE);
        for (int i = 0; i < CONCURRENT_SIZE; i++) {
            generators.add(new ServiceTicketGenerator(newTgt.getId(), this.jpaTicketRegistry, this.txManager));
        }
        final List<Future<String>> results = executor.invokeAll(generators);
        for (final Future<String> result : results) {
            assertNotNull(result.get());
        }
    } catch (final Exception e) {
        logger.debug("testConcurrentServiceTicketGeneration produced an error", e);
        fail("testConcurrentServiceTicketGeneration failed.");
    } finally {
        executor.shutdownNow();
    }
}
 
Example #8
Source File: ProfileValueChecker.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Determine if the test specified by arguments to the
 * {@linkplain #ProfileValueChecker constructor} is <em>enabled</em> in
 * the current environment, as configured via the {@link IfProfileValue
 * &#064;IfProfileValue} annotation.
 * <p>If the test is not annotated with {@code @IfProfileValue} it is
 * considered enabled.
 * <p>If a test is not enabled, this method will abort further evaluation
 * of the execution chain with a failed assumption; otherwise, this method
 * will simply evaluate the next {@link Statement} in the execution chain.
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class)
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class)
 * @see org.junit.Assume
 */
@Override
public void evaluate() throws Throwable {
	if (this.testMethod == null) {
		if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testClass)) {
			// Invoke assumeTrue() with false to avoid direct reference to JUnit's
			// AssumptionViolatedException which exists in two packages as of JUnit 4.12.
			Annotation ann = AnnotationUtils.findAnnotation(this.testClass, IfProfileValue.class);
			Assume.assumeTrue(String.format(
					"Profile configured via [%s] is not enabled in this environment for test class [%s].",
					ann, this.testClass.getName()), false);
		}
	}
	else {
		if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testMethod, this.testClass)) {
			// Invoke assumeTrue() with false to avoid direct reference to JUnit's
			// AssumptionViolatedException which exists in two packages as of JUnit 4.12.
			Assume.assumeTrue(String.format(
					"Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].",
					this.testMethod), false);
		}
	}

	this.next.evaluate();
}
 
Example #9
Source File: ProfileValueChecker.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Determine if the test specified by arguments to the
 * {@linkplain #ProfileValueChecker constructor} is <em>enabled</em> in
 * the current environment, as configured via the {@link IfProfileValue
 * &#064;IfProfileValue} annotation.
 * <p>If the test is not annotated with {@code @IfProfileValue} it is
 * considered enabled.
 * <p>If a test is not enabled, this method will abort further evaluation
 * of the execution chain with a failed assumption; otherwise, this method
 * will simply evaluate the next {@link Statement} in the execution chain.
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class)
 * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class)
 * @throws AssumptionViolatedException if the test is disabled
 * @throws Throwable if evaluation of the next statement fails
 */
@Override
public void evaluate() throws Throwable {
	if (this.testMethod == null) {
		if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testClass)) {
			Annotation ann = AnnotatedElementUtils.findMergedAnnotation(this.testClass, IfProfileValue.class);
			throw new AssumptionViolatedException(String.format(
					"Profile configured via [%s] is not enabled in this environment for test class [%s].",
					ann, this.testClass.getName()));
		}
	}
	else {
		if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testMethod, this.testClass)) {
			throw new AssumptionViolatedException(String.format(
					"Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].",
					this.testMethod));
		}
	}

	this.next.evaluate();
}
 
Example #10
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabases({
		@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource1.result.xml"),
		@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource2.result.xml"), })
@DatabaseTearDowns({
		@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource1.result.xml"),
		@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne2.datasource2.result.xml"), })
public void testNPlusOne2() {
	Role2_ r = new Role2_();
	r.setId(1);
	r.setName("root");
	role2Service.insert(r);

	Role2_ r2 = new Role2_();
	r2.setId(2);
	r2.setName("user");
	role2Service.insert(r2);

	Account22 a = new Account22();
	a.setId(21);
	a.setEmail("10");
	a.setRole(r);
	account22Service.insert(a);

	Account22 a2 = new Account22();
	a2.setId(22);
	a2.setEmail("11");
	a2.setRole(r);
	account22Service.insert(a2);

	Collection<Account22> accounts = account22Service.selectAll(new Account22());
	Assert.assertEquals(2, accounts.size());
	Collection<Account22> accounts2 = account22Service.selectAll(new Account22());
	Collection<Account22> accounts3 = account22Service.selectAll(new Account22());
}
 
Example #11
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne.datasource2.result.xml")
@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNPlusOne.datasource2.result.xml")
public void testNPlusOne() {
	Role2_ r = new Role2_();
	r.setId(1);
	r.setName("root");
	role2Service.insert(r);

	Role2_ r2 = new Role2_();
	r2.setId(2);
	r2.setName("user");
	role2Service.insert(r2);

	Account2_ a = new Account2_();
	a.setId(21);
	a.setEmail("10");
	a.setRole(r);
	account2Service.insert(a);

	Account2_ a2 = new Account2_();
	a2.setId(22);
	a2.setEmail("11");
	a2.setRole(r);
	account2Service.insert(a2);

	Collection<Account2_> accounts = account2Service.selectAll(new Account2_());
	Assert.assertEquals(2, accounts.size());
}
 
Example #12
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testCacheHit.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testCacheHit.result.xml")
public void testCacheHit() {
	Role_ role1 = new Role_(), role2 = new Role_();
	role1.setName("silver");
	roleService.insert(role1);

	role2.setName("gold");
	roleService.insert(role2);

	Account_ a1 = new Account_(), a2 = new Account_(), a3 = new Account_();
	a1.setName("ann");
	a1.setRole(role1);
	accountService.insert(a1);

	a2.setName("bob");
	a2.setRole(role1);
	accountService.insert(a2);

	a3.setName("cal");
	a3.setRole(role2);
	accountService.insert(a3);

	Account_ ac1 = new Account_();
	Role_ rc1 = new Role_();
	rc1.setId(role1.getId());
	ac1.setRole(rc1);
	Collection<Account_> accountC1 = accountService.selectAll(ac1);
	Assert.assertEquals(2, accountC1.size());

	Account_ ac2 = new Account_();
	Role_ rc2 = new Role_();
	rc2.setId(role2.getId());
	ac2.setRole(rc2);
	Collection<Account_> accountC2 = accountService.selectAll(ac2);
	Assert.assertEquals(1, accountC2.size());
}
 
Example #13
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSelectWithoutRole.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSelectWithoutRole.result.xml")
public void testSelectWithoutRole() {
	Role_ r = new Role_(), r2 = new Role_();
	r.setId(1);
	r.setName("root");
	roleService.insert(r);

	r2.setId(2);
	r2.setName("user");
	roleService.insert(r2);

	Account_ a = new Account_();
	a.setId(1L);
	a.setRole(r);
	a.setRoleDeputy(r2);
	a.setName("deployer");
	accountService.insert(a);

	Account_ account = accountService.selectWithoutRole(1);
	Assert.assertNull(account.getRole());
	Assert.assertEquals("2", account.getRoleDeputy().getId().toString());

	roleService.update(r);

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 2);
	m.put("name", "newUser");
	roleService.updateDirect(m);

	Account_ account2 = accountService.selectWithoutRole(1);
	Assert.assertEquals("newUser", account2.getRoleDeputy().getName());
}
 
Example #14
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSameIdAndInjectionInDifferentPojos.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSameIdAndInjectionInDifferentPojos.result.xml")
public void testSameIdAndInjectionInDifferentPojos() {
	Role_ r = new Role_();
	r.setId(1);
	r.setName("root");
	roleService.insert(r);

	Account_ a = new Account_();
	a.setId(1L);
	a.setName("deployer");
	accountService.insert(a);

	Role_ role = roleService.selectEverything(1);
	Account_ account = accountService.selectEverything(1);

	a.setName("newDeployer");
	accountService.update(a);

	Account_ account2 = accountService.selectEverything(1);
	Assert.assertEquals("newDeployer", account2.getName());

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 1);
	m.put("name", "newRoot");
	roleService.updateDirect(m);

	Role_ role2 = roleService.selectEverything(1);
	Assert.assertEquals("root", role2.getName());
}
 
Example #15
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testNearlySameInjection.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testNearlySameInjection.result.xml")
public void testNearlySameInjection() {
	Role_ r = new Role_(), r2 = new Role_();

	r.setId(1);
	r.setName("root");
	roleService.insert(r);

	r2.setId(2);
	r2.setName("deployer");
	roleService.insert(r2);

	Role_ role = roleService.select(1);
	Assert.assertEquals("root", role.getName());

	Role_ role2 = roleService.selectNoId(1);
	Assert.assertEquals("root", role2.getName());
	Assert.assertNull(role2.getId());

	r.setName("newRoot");
	roleService.update(r);

	Role_ role3 = roleService.select(1);
	Assert.assertEquals("newRoot", role3.getName());

	Role_ role4 = roleService.selectNoId(1);
	Assert.assertEquals("newRoot", role4.getName());
	Assert.assertNull(role4.getId());
}
 
Example #16
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testSameInjection.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testSameInjection.result.xml")
public void testSameInjection() {
	Role_ r = new Role_(), r2 = new Role_();

	r.setId(1);
	r.setName("root");
	roleService.insert(r);

	r2.setId(2);
	r2.setName("deployer");
	roleService.insert(r2);

	Role_ role = roleService.select(1);
	Assert.assertEquals("root", role.getName());

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 1);
	m.put("name", "newRoot");
	roleService.updateDirect(m);

	Role_ role2 = roleService.select(1);
	Assert.assertEquals("root", role2.getName());

	Role_ role3 = roleService.selectEverything(1);
	Assert.assertEquals("newRoot", role3.getName());
}
 
Example #17
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect4() {
	Role_ r = new Role_();
	r.setId(1);
	r.setName("ann");
	roleService.insert(r);
	Account_ a = new Account_();
	a.setId(1L);
	a.setRole(r);
	a.setEmail("email");
	accountService.insert(a);

	Account_Condition ac = new Account_Condition();
	ac.setLimiter(new PageParam(1, 1));
	Collection<Account_> c = accountService.selectAll(ac);

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 1);
	m.put("name", "bob");
	roleService.updateDirect(m);

	Account_Condition ac2 = new Account_Condition();
	ac2.setLimiter(new PageParam(1, 1));
	Collection<Account_> c2 = accountService.selectAll(ac2);
	for (Account_ t : c2) {
		Assert.assertEquals("ann", t.getRole().getName());
	}
}
 
Example #18
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect3() {
	Role_ r = new Role_();
	r.setId(1);
	r.setName("ann");
	roleService.insert(r);
	Account_ a = new Account_();
	a.setId(1L);
	a.setRole(r);
	a.setEmail("email");
	accountService.insert(a);

	Account_Condition ac = new Account_Condition();
	ac.setEmailLike("mai");
	Collection<Account_> c = accountService.selectAll(ac);

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 1);
	m.put("name", "bob");
	roleService.updateDirect(m);

	Account_Condition ac2 = new Account_Condition();
	ac2.setEmailLike("mai");
	Collection<Account_> c2 = accountService.selectAll(ac2);
	for (Account_ t : c2) {
		Assert.assertEquals("ann", t.getRole().getName());
	}
}
 
Example #19
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testUpdateDirect.result.xml")
public void testUpdateDirect2() {
	Role_ r = new Role_();
	r.setId(1);
	r.setName("ann");
	roleService.insert(r);
	Account_ a = new Account_();
	a.setId(1L);
	a.setRole(r);
	a.setEmail("email");
	accountService.insert(a);

	Account_ ac = new Account_();
	ac.setEmail("email");
	Collection<Account_> c = accountService.selectAll(ac);

	Map<String, Object> m = new HashMap<>(4);
	m.put("id", 1);
	m.put("name", "bob");
	roleService.updateDirect(m);

	Account_ ac2 = new Account_();
	ac2.setEmail("email");
	Collection<Account_> c2 = accountService.selectAll(ac2);
	for (Account_ t : c2) {
		Assert.assertEquals("ann", t.getRole().getName());
	}
}
 
Example #20
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@ExpectedDatabase(connection = "dataSource1", assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED, value = "/indi/mybatis/flying/test/cacheTest/testPaginationUsingCacheIndeed.result.xml")
@DatabaseTearDown(connection = "dataSource1", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/testPaginationUsingCacheIndeed.result.xml")
public void testPaginationUsingCacheIndeed() {
	Role_ role1 = new Role_(), role2 = new Role_(), role3 = new Role_();
	role1.setName("normal");
	roleService.insert(role1);

	role2.setName("silver");
	roleService.insert(role2);

	role3.setName("gold");
	roleService.insert(role3);

	Role_Condition rc = new Role_Condition();
	rc.setLimiter(new PageParam(1, 2));
	rc.setSorter(new SortParam(new Order("name", Conditionable.Sequence.ASC)));
	Collection<Role_> c1 = roleService.selectAll(rc);
	Assert.assertEquals(2, c1.size());
	Role_[] roles = c1.toArray(new Role_[c1.size()]);
	Assert.assertEquals("gold", roles[0].getName());

	Map<String, Object> m = new HashMap<>(4);
	m.put("name", "gold1");
	m.put("id", roles[0].getId());
	roleService.updateDirect(m);

	Role_Condition rc2 = new Role_Condition();
	rc2.setLimiter(new PageParam(1, 2));
	rc2.setSorter(new SortParam(new Order("name", Conditionable.Sequence.ASC)));
	Collection<Role_> c2 = roleService.selectAll(rc2);
	Assert.assertEquals(2, c2.size());
	Role_[] roles2 = c2.toArray(new Role_[c2.size()]);
	Assert.assertEquals("gold", roles2[0].getName());
}
 
Example #21
Source File: BucketsIT.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name="current.database.is.h2", value="true")
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:db/clearDB.sql", "classpath:db/BucketsIT.sql"})
public void testGetBuckets() throws Exception {

    // Given: these buckets have been populated in the DB (see BucketsIT.sql)

    String expected = "[" +
            "{\"identifier\":\"1\"," +
            "\"name\":\"Bucket 1\"," +
            "\"createdTimestamp\":1505134260000," +
            "\"description\":\"This is test bucket 1\"," +
            "\"permissions\":{\"canRead\":true,\"canWrite\":true,\"canDelete\":true}," +
            "\"link\":{\"params\":{\"rel\":\"self\"},\"href\":\"buckets/1\"}}," +
            "{\"identifier\":\"2\"," +
            "\"name\":\"Bucket 2\"," +
            "\"createdTimestamp\":1505134320000," +
            "\"description\":\"This is test bucket 2\"," +
            "\"permissions\":{\"canRead\":true,\"canWrite\":true,\"canDelete\":true}," +
            "\"link\":{\"params\":{\"rel\":\"self\"},\"href\":\"buckets/2\"}}," +
            "{\"identifier\":\"3\"," +
            "\"name\":\"Bucket 3\"," +
            "\"createdTimestamp\":1505134380000," +
            "\"description\":\"This is test bucket 3\"," +
            "\"permissions\":{\"canRead\":true,\"canWrite\":true,\"canDelete\":true}," +
            "\"link\":{\"params\":{\"rel\":\"self\"},\"href\":\"buckets/3\"}}" +
            "]";

    // When: the /buckets endpoint is queried

    String bucketsJson = client
            .target(createURL("buckets"))
            .request()
            .get(String.class);

    // Then: the pre-populated list of buckets is returned

    JSONAssert.assertEquals(expected, bucketsJson, false);
    assertTrue(!bucketsJson.contains("null")); // JSON serialization from the server should not include null fields, such as "versionedFlows": null
}
 
Example #22
Source File: CacheTest1.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test2.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest/test2.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest/test2.result.xml")
public void test2() {
	String name = "新权限", newName = "新角色", accountName = "ann", ip = "0.0.0.1";
	Role_ r = new Role_();
	r.setName(name);
	roleService.insert(r);

	Account_ a = new Account_();
	a.setName(accountName);
	a.setRole(r);
	accountService.insert(a);

	LoginLog_ l = new LoginLog_();
	l.setLoginIP(ip);
	l.setAccount(a);
	loginLogService.insert(l);

	Account_ account = accountService.select(a.getId());
	Assert.assertEquals(name, account.getRole().getName());

	LoginLog_ loginLog = loginLogService.select(l.getId());
	Assert.assertEquals(name, loginLog.getAccount().getRole().getName());

	Role_ role = roleService.select(r.getId());
	role.setName(newName);
	roleService.update(role);

	Account_ account2 = accountService.select(a.getId());
	Assert.assertEquals(newName, account2.getRole().getName());

	LoginLog_ loginLog2 = loginLogService.select(l.getId());
	Assert.assertEquals(newName, loginLog2.getAccount().getRole().getName());
}
 
Example #23
Source File: FlowsIT.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name="current.database.is.h2", value="true")
public void testGetFlowVersions() throws Exception {

    // Given: a bucket "1" with flow "1" with existing snapshots has been populated in the DB (see FlowsIT.sql)

    final String prePopulatedBucketId = "1";
    final String prePopulatedFlowId = "1";
    // For this test case, the order of the expected list matters as we are asserting a strict equality check
    final String expected = "[" +
            "{\"bucketIdentifier\":\"1\"," +
            "\"flowIdentifier\":\"1\"," +
            "\"version\":2," +
            "\"timestamp\":1505174400000," +
            "\"author\" : \"user2\"," +
            "\"comments\":\"This is flow 1 snapshot 2\"," +
            "\"link\":{\"params\":{\"rel\":\"content\"},\"href\":\"buckets/1/flows/1/versions/2\"}}," +
            "{\"bucketIdentifier\":\"1\"," +
            "\"flowIdentifier\":\"1\"," +
            "\"version\":1," +
            "\"timestamp\":1505088000000," +
            "\"author\" : \"user1\"," +
            "\"comments\":\"This is flow 1 snapshot 1\"," +
            "\"link\":{\"params\":{\"rel\":\"content\"},\"href\":\"buckets/1/flows/1/versions/1\"}}" +
            "]";

    // When: the /buckets/{id}/flows/{id}/versions endpoint is queried
    final String flowSnapshotsJson = client
            .target(createURL("buckets/{bucketId}/flows/{flowId}/versions"))
            .resolveTemplate("bucketId", prePopulatedBucketId)
            .resolveTemplate("flowId", prePopulatedFlowId)
            .request()
            .get(String.class);

    // Then: the pre-populated list of flow versions is returned, in descending order
    JSONAssert.assertEquals(expected, flowSnapshotsJson, true);

}
 
Example #24
Source File: JpaLockingStrategyTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * Test concurrent acquire/release semantics.
 */
@Test
@IfProfileValue(name="cas.jpa.concurrent", value="true")
public void testConcurrentAcquireAndRelease() throws Exception {
    final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE);
    try {
        testConcurrency(executor, getConcurrentLocks("concurrent-new"));
    } catch (final Exception e) {
        logger.debug("testConcurrentAcquireAndRelease produced an error", e);
        fail("testConcurrentAcquireAndRelease failed.");
    } finally {
        executor.shutdownNow();
    }
}
 
Example #25
Source File: TwitterCrawlerTests.java    From sentiment-analysis-twitter-microservices-example with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name = "test")
public void crawlUser() {
    ResponseEntity<User> user1 = new TestRestTemplate().getForEntity("http://localhost:" + port + "/v1/user/kennybastani", User.class);
    assertEquals(HttpStatus.OK, user1.getStatusCode());
    ResponseEntity<User> user2 = new TestRestTemplate().getForEntity("http://localhost:" + port + "/v1/user/bridgetkromhout", User.class);
    assertEquals(HttpStatus.OK, user2.getStatusCode());
    ResponseEntity<User> user3 = new TestRestTemplate().getForEntity("http://localhost:" + port + "/v1/user/starbuxman", User.class);
    assertEquals(HttpStatus.OK, user3.getStatusCode());
}
 
Example #26
Source File: JpaLockingStrategyTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Test concurrent acquire/release semantics.
 */
@Test
@IfProfileValue(name="cas.jpa.concurrent", value="true")
public void verifyConcurrentAcquireAndRelease() throws Exception {
    final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE);
    try {
        testConcurrency(executor, getConcurrentLocks("concurrent-new"));
    } catch (final Exception e) {
        logger.debug("testConcurrentAcquireAndRelease produced an error", e);
        fail("testConcurrentAcquireAndRelease failed.");
    } finally {
        executor.shutdownNow();
    }
}
 
Example #27
Source File: FlowsIT.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Test
@IfProfileValue(name="current.database.is.h2", value="true")
public void testGetFlows() throws Exception {

    // Given: a few buckets and flows have been populated in the DB (see FlowsIT.sql)

    final String prePopulatedBucketId = "1";
    final String expected = "[" +
            "{\"identifier\":\"1\"," +
            "\"name\":\"Flow 1\"," +
            "\"description\":\"This is flow 1\"," +
            "\"bucketIdentifier\":\"1\"," +
            "\"createdTimestamp\":1505088000000," +
            "\"modifiedTimestamp\":1505088000000," +
            "\"type\":\"Flow\"," +
            "\"permissions\":{\"canRead\":true,\"canWrite\":true,\"canDelete\":true}," +
            "\"link\":{\"params\":{\"rel\":\"self\"},\"href\":\"buckets/1/flows/1\"}}," +
            "{\"identifier\":\"2\",\"name\":\"Flow 2\"," +
            "\"description\":\"This is flow 2\"," +
            "\"bucketIdentifier\":\"1\"," +
            "\"createdTimestamp\":1505088000000," +
            "\"modifiedTimestamp\":1505088000000," +
            "\"type\":\"Flow\"," +
            "\"permissions\":{\"canRead\":true,\"canWrite\":true,\"canDelete\":true}," +
            "\"versionCount\":0," +
            "\"link\":{\"params\":{\"rel\":\"self\"},\"href\":\"buckets/1/flows/2\"}}" +
            "]";

    // When: the /buckets/{id}/flows endpoint is queried

    final String flowsJson = client
            .target(createURL("buckets/{bucketId}/flows"))
            .resolveTemplate("bucketId", prePopulatedBucketId)
            .request()
            .get(String.class);

    // Then: the pre-populated list of flows is returned

    JSONAssert.assertEquals(expected, flowsJson, false);
}
 
Example #28
Source File: EnabledAndIgnoredSpringRunnerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
@IfProfileValue(name = NAME, values = { "foo", VALUE, "bar" })
public void testIfProfileValueEnabledViaMultipleValues() {
	numTestsExecuted++;
}
 
Example #29
Source File: EnabledAndIgnoredSpringRunnerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
@IfProfileValue(name = NAME, value = VALUE)
public void testIfProfileValueEnabledViaSingleValue() {
	numTestsExecuted++;
}
 
Example #30
Source File: EnabledAndIgnoredSpringRunnerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
@IfProfileValue(name = NAME, value = VALUE + "X")
public void testIfProfileValueDisabled() {
	numTestsExecuted++;
	fail("The body of a disabled test should never be executed!");
}