当前位置: 首页>>代码示例>>Java>>正文


Java TestUtils类代码示例

本文整理汇总了Java中com.holonplatform.core.internal.utils.TestUtils的典型用法代码示例。如果您正苦于以下问题:Java TestUtils类的具体用法?Java TestUtils怎么用?Java TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestUtils类属于com.holonplatform.core.internal.utils包,在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUtils

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testUtils() {

	ORMPlatform ptf = ORMPlatform.resolve(entityManager);
	assertNotNull(ptf);
	assertEquals(ORMPlatform.HIBERNATE, ptf);

	TestUtils.expectedException(IllegalArgumentException.class, new Runnable() {

		@Override
		public void run() {
			ORMPlatform.resolve(null);
		}
	});

}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:17,代码来源:TestBase.java

示例2: testRealmContext

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testRealmContext() {

	TestUtils.expectedException(IllegalStateException.class, new Runnable() {

		@Override
		public void run() {
			Realm.require();
		}
	});

	String name = Context.get().executeThreadBound(Realm.CONTEXT_KEY,
			Realm.builder().name("rlm").withDefaultAuthorizer().build(), () -> {
				return Realm.getCurrent().orElseThrow(() -> new IllegalStateException("Missing Realm")).getName()
						.orElse(null);
			});

	assertEquals("rlm", name);

}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:21,代码来源:TestRealm.java

示例3: testNotEmpty

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testNotEmpty() {
	Validator.notEmpty().validate("a");
	TestUtils.expectedException(ValidationException.class, () -> Validator.notEmpty().validate(null));
	TestUtils.expectedException(ValidationException.class, () -> Validator.notEmpty().validate(""));

	Validator.notEmpty().validate(Collections.singleton(1));
	TestUtils.expectedException(ValidationException.class,
			() -> Validator.notEmpty().validate(Collections.emptySet()));

	Validator.notEmpty().validate(Collections.singletonMap("a", 1));
	TestUtils.expectedException(ValidationException.class,
			() -> Validator.notEmpty().validate(Collections.emptyMap()));

	Validator.notEmpty().validate(new String[] { "a" });
	TestUtils.expectedException(ValidationException.class, () -> Validator.notEmpty().validate(new String[0]));

	TestUtils.expectedException(UnsupportedValidationTypeException.class, () -> Validator.notEmpty().validate(1));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:20,代码来源:TestValidators.java

示例4: testMin

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testMin() {
	Validator.min(1).validate(null);
	Validator.min(1).validate("a");
	Validator.min(1).validate("ab");
	Validator.min(1).validate(1);
	Validator.min(1).validate(2);
	Validator.min(1).validate(1d);
	Validator.min(1).validate(1.1d);
	Validator.min(1).validate(1L);
	Validator.min(1).validate(BigDecimal.valueOf(1));
	Validator.min(1).validate(BigInteger.valueOf(1));
	Validator.min(1).validate(Collections.singleton(1));
	Validator.min(1).validate(Collections.singletonMap("a", 1));
	Validator.min(1).validate(new String[] { "a" });

	TestUtils.expectedException(ValidationException.class, () -> Validator.min(1).validate(""));
	TestUtils.expectedException(ValidationException.class, () -> Validator.min(1).validate(0));
	TestUtils.expectedException(ValidationException.class, () -> Validator.min(2).validate(1.5d));
	TestUtils.expectedException(ValidationException.class, () -> Validator.min(1).validate(Collections.emptySet()));
	TestUtils.expectedException(ValidationException.class, () -> Validator.min(1).validate(Collections.emptyMap()));
	TestUtils.expectedException(ValidationException.class, () -> Validator.min(1).validate(new String[0]));

	TestUtils.expectedException(UnsupportedValidationTypeException.class,
			() -> Validator.min(1).validate(new Date()));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:27,代码来源:TestValidators.java

示例5: testBase

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testBase() {

	TestUtils.checkEnum(TemporalType.class);
	TestUtils.checkEnum(TemporalFormat.class);
	TestUtils.checkEnum(NumberFormatFeature.class);

	Localization lc = Localization.builder(Locale.ITALY).defaultDecimalPositions(2)
			.defaultDateTemporalFormat(TemporalFormat.MEDIUM).defaultTimeTemporalFormat(TemporalFormat.SHORT)
			.build();

	assertEquals(Locale.ITALY, lc.getLocale());
	assertEquals(new Integer(2), lc.getDefaultDecimalPositions().get());
	assertEquals(TemporalFormat.MEDIUM, lc.getDefaultDateTemporalFormat().get());
	assertEquals(TemporalFormat.SHORT, lc.getDefaultTimeTemporalFormat().get());

	DefaultLocalization l2 = new DefaultLocalization(Locale.US);

	Localization lp = Localization.builder(Locale.ITALY).parent(l2).build();
	assertEquals(l2, lp.getParent().get());

	assertNotEquals(lc, l2);
	assertNotEquals(lc, null);
	assertEquals(lc, lc);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:26,代码来源:TestI18n.java

示例6: testContainerUtils

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testContainerUtils() {
	assertNotNull(ContainerUtils.getQueryExpression(TestData.ID, CFG));

	assertNull(ContainerUtils.getQueryExpression(null, CFG));

	TestUtils.expectedException(InvalidExpressionException.class, new Callable<Void>() {

		@Override
		public Void call() throws InvalidExpressionException {
			ContainerUtils.getQueryExpression("invalid", CFG);
			return null;
		}
	});
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:16,代码来源:TestItems.java

示例7: testErrors

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testErrors() {
	final RestClient client = JaxrsRestClient.create(getClient()).defaultTarget(getBaseUri());

	ResponseEntity<?> rsp = client.request().path("test").path("data/save")
			.put(RequestEntity.json(new TestData(-1, "testErr")));

	assertNotNull(rsp);
	assertEquals(HttpStatus.BAD_REQUEST, rsp.getStatus());

	ApiError error = rsp.as(ApiError.class).orElse(null);
	assertNotNull(error);
	assertEquals("ERR000", error.getCode());

	ResponseEntity<TestData> r2 = client.request().path("test").path("data2/{id}").resolve("id", -1)
			.get(TestData.class);
	assertNotNull(r2);
	assertEquals(HttpStatus.BAD_REQUEST, r2.getStatus());

	error = r2.as(ApiError.class).orElse(null);
	assertNotNull(error);
	assertEquals("ERR000", error.getCode());

	TestUtils.expectedException(UnsuccessfulResponseException.class, () -> {
		client.request().path("test").path("data2/{id}").resolve("id", -1).getForEntity(TestData.class)
				.orElse(null);
	});

	try {
		client.request().path("test").path("data2/{id}").resolve("id", -1).getForEntity(TestData.class)
				.orElse(null);
	} catch (UnsuccessfulResponseException e) {
		assertEquals(HttpStatus.BAD_REQUEST, e.getStatus().orElse(null));
		assertNotNull(e.getResponse());

		ApiError err = e.getResponse().as(ApiError.class).orElse(null);
		assertNotNull(err);
		assertEquals("ERR000", err.getCode());
	}
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:41,代码来源:TestJaxrsClient.java

示例8: testHttp

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testHttp() throws URISyntaxException {

	TestUtils.checkUtilityClass(HttpUtils.class);

	assertFalse(HttpUtils.isSecure(null));
	assertTrue(HttpUtils.isSecure(new URI("https://example.com/test")));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:TestHttp.java

示例9: testCredentialsEncoder

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testCredentialsEncoder() throws UnsupportedEncodingException {

	TestUtils.expectedException(IllegalStateException.class, new Runnable() {

		@Override
		public void run() {
			Credentials.encoder().build();
		}
	});

	final String secret = "test";
	final byte[] secretBytes = ConversionUtils.toBytes(secret);

	byte[] bytes = Credentials.encoder().secret(secret).build();
	assertTrue(Arrays.equals(secretBytes, bytes));

	String sb = Credentials.encoder().secret(secret).buildAndEncodeBase64();
	assertEquals(Base64.getEncoder().encodeToString(secret.getBytes("UTF-8")), sb);

	bytes = Credentials.encoder().secret(secret).hashMD5().build();
	assertNotNull(bytes);
	bytes = Credentials.encoder().secret(secret).hashSHA1().build();
	assertNotNull(bytes);
	bytes = Credentials.encoder().secret(secret).hashSHA256().build();
	assertNotNull(bytes);
	bytes = Credentials.encoder().secret(secret).hashSHA384().build();
	assertNotNull(bytes);
	bytes = Credentials.encoder().secret(secret).hashSHA512().charset("UTF-8").build();
	assertNotNull(bytes);

	TestUtils.expectedException(RuntimeException.class, new Runnable() {

		@Override
		public void run() {
			Credentials.encoder().secret("test").hashAlgorithm("xxx").build();
		}
	});

}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:41,代码来源:TestCredentials.java

示例10: testAuthContextResource

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testAuthContextResource() {

	TestUtils.expectedException(IllegalStateException.class, new Runnable() {

		@Override
		public void run() {
			AuthContext.require();
		}
	});

	boolean ia = Context.get().executeThreadBound(AuthContext.CONTEXT_KEY,
			AuthContext.create(Realm.builder().withDefaultAuthorizer().build()), () -> {
				return AuthContext.getCurrent().orElseThrow(() -> new IllegalStateException("Missing AuthContext"))
						.isAuthenticated();
			});

	assertFalse(ia);

	ia = Context.get().executeThreadBound(AuthContext.CONTEXT_KEY,
			AuthContext.create(Realm.builder().withDefaultAuthorizer().build()), () -> {
				return AuthContext.require().isAuthenticated();
			});

	assertFalse(ia);

}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:28,代码来源:TestAuthContext.java

示例11: testNotBlank

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testNotBlank() {
	Validator.notBlank().validate("a");

	TestUtils.expectedException(ValidationException.class, () -> Validator.notBlank().validate(null));
	TestUtils.expectedException(ValidationException.class, () -> Validator.notBlank().validate(""));
	TestUtils.expectedException(ValidationException.class, () -> Validator.notBlank().validate(" "));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:TestValidators.java

示例12: testMax

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testMax() {
	Validator.max(1).validate(null);
	Validator.max(2).validate("ab");
	Validator.max(1).validate(1);
	Validator.max(1).validate(0);
	Validator.max(1).validate(1d);
	Validator.max(5).validate(4.9d);
	Validator.max(3).validate(2L);
	Validator.max(2).validate(BigDecimal.valueOf(1));
	Validator.max(1).validate(BigInteger.valueOf(1));
	Validator.max(2).validate(Collections.singleton(1));
	Validator.max(1).validate(Collections.singletonMap("a", 1));
	Validator.max(3).validate(new String[] { "a", "b" });

	TestUtils.expectedException(ValidationException.class, () -> Validator.max(1).validate("ab"));
	TestUtils.expectedException(ValidationException.class, () -> Validator.max(1).validate(2));
	TestUtils.expectedException(ValidationException.class, () -> Validator.max(2).validate(2.1d));
	TestUtils.expectedException(ValidationException.class,
			() -> Validator.max(0).validate(Collections.singleton(1)));
	TestUtils.expectedException(ValidationException.class,
			() -> Validator.max(0).validate(Collections.singletonMap("a", 1)));
	TestUtils.expectedException(ValidationException.class,
			() -> Validator.max(1).validate(new String[] { "a", "b" }));

	TestUtils.expectedException(UnsupportedValidationTypeException.class,
			() -> Validator.max(1).validate(new Date()));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:29,代码来源:TestValidators.java

示例13: testPattern

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testPattern() {
	Validator.pattern("a").validate(null);

	Validator.pattern("\\d+").validate("012");

	TestUtils.expectedException(ValidationException.class, () -> Validator.pattern("\\d+").validate("a1"));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:TestValidators.java

示例14: testIn

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testIn() {
	Validator.in(1, 2).validate(2);

	TestUtils.expectedException(ValidationException.class, () -> Validator.in(1, 2).validate(null));
	TestUtils.expectedException(ValidationException.class, () -> Validator.in(1, 2).validate(3));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:8,代码来源:TestValidators.java

示例15: testNotIn

import com.holonplatform.core.internal.utils.TestUtils; //导入依赖的package包/类
@Test
public void testNotIn() {
	Validator.notIn(1, 2).validate(3);
	Validator.notIn(1, 2).validate(null);

	TestUtils.expectedException(ValidationException.class, () -> Validator.notIn(1, 2).validate(1));
	TestUtils.expectedException(ValidationException.class, () -> Validator.notIn(1, 2).validate(2));
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:TestValidators.java


注:本文中的com.holonplatform.core.internal.utils.TestUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。