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


Java TestUtils.expectedException方法代码示例

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


在下文中一共展示了TestUtils.expectedException方法的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: 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

示例3: 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

示例4: 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

示例5: testBeanPropertyBox

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

	Date date = new Date();

	TestBean test = new TestBean();
	test.setName("Test");
	test.setSequence(1);
	TestNested testNested = new TestNested();
	testNested.setNestedId(2L);
	testNested.setNestedDate(date);
	test.setNested(testNested);

	final PropertyBox box = PropertyBox.builder(TestPropertySet.PROPERTIES).build();
	BeanIntrospector.get().read(box, test);

	assertTrue(box.size() > 0);

	Object value = box.getValue(TestPropertySet.NAME);
	assertEquals("Test", value);

	value = box.getValue(TestPropertySet.NESTED_ID);
	assertNotNull(value);
	assertEquals(Long.valueOf(2L), value);

	value = box.getValue(TestPropertySet.NESTED_DATE);
	assertNotNull(value);

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

		@Override
		public void run() {
			PathProperty<String> px = PathProperty.create("px", String.class);
			box.getValue(px);
		}
	});

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

示例6: 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

示例7: 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

示例8: testFactoryBean

import com.holonplatform.core.internal.utils.TestUtils; //导入方法依赖的package包/类
@Test
public void testFactoryBean() {
	TestUtils.expectedException(BeanInitializationException.class, new Callable<DataSource>() {

		@Override
		public DataSource call() throws Exception {
			FactoryBean<DataSource> fb = new DataSourceFactoryBean(
					SpringDataSourceConfigProperties.builder().withPropertySource(new Properties()).build());
			return fb.getObject();
		}
	});
}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:13,代码来源:TestBase.java

示例9: 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

示例10: testGreater

import com.holonplatform.core.internal.utils.TestUtils; //导入方法依赖的package包/类
@Test
public void testGreater() {
	Validator.greaterThan(3).validate(4);
	TestUtils.expectedException(ValidationException.class, () -> Validator.greaterThan(3).validate(3));
	TestUtils.expectedException(ValidationException.class, () -> Validator.greaterThan(3).validate(2));

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

示例11: testDate

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

	Calendar c = Calendar.getInstance();

	Calendar c1 = (Calendar) c.clone();
	c1.add(Calendar.DATE, -1);

	Validator.past(false).validate(c1.getTime());

	Calendar c2 = (Calendar) c.clone();
	c2.add(Calendar.HOUR_OF_DAY, -1);

	Validator.past(true).validate(c1.getTime());

	TestUtils.expectedException(ValidationException.class, () -> Validator.past(false).validate(c.getTime()));

	Calendar c3 = Calendar.getInstance();
	c3.add(Calendar.DATE, 1);
	Calendar c4 = Calendar.getInstance();
	c4.add(Calendar.HOUR_OF_DAY, 1);

	TestUtils.expectedException(ValidationException.class, () -> Validator.past(false).validate(c3.getTime()));
	TestUtils.expectedException(ValidationException.class, () -> Validator.past(true).validate(c4.getTime()));

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

示例12: testPropertyBoxItem

import com.holonplatform.core.internal.utils.TestUtils; //导入方法依赖的package包/类
@Test
public void testPropertyBoxItem() {
	PropertyBox box = PropertyBox.builder(TestData.PROPERTIES).set(TestData.ID, "id")
			.set(TestData.DESCRIPTION, "des").set(TestData.SEQUENCE, 1).set(TestData.OBSOLETE, true).build();

	final Item item = PropertyBoxItem.create(box);

	Collection<?> ids = item.getItemPropertyIds();
	assertNotNull(ids);
	assertEquals(4, ids.size());
	assertTrue(ids.contains(TestData.ID));
	assertTrue(ids.contains(TestData.DESCRIPTION));
	assertTrue(ids.contains(TestData.SEQUENCE));
	assertTrue(ids.contains(TestData.OBSOLETE));

	Property<?> p = item.getItemProperty(TestData.ID);
	assertNotNull(p);
	Class<?> type = p.getType();
	assertEquals(String.class, type);
	Object value = p.getValue();
	assertEquals("id", value);

	p = item.getItemProperty(TestData.DESCRIPTION);
	assertNotNull(p);
	type = p.getType();
	assertEquals(String.class, type);
	value = p.getValue();
	assertEquals("des", value);

	p = item.getItemProperty(TestData.SEQUENCE);
	assertNotNull(p);
	type = p.getType();
	assertEquals(Integer.class, type);
	value = p.getValue();
	assertEquals(1, value);

	p = item.getItemProperty(TestData.OBSOLETE);
	assertNotNull(p);
	type = p.getType();
	assertTrue(Boolean.class.isAssignableFrom(type));
	value = p.getValue();
	assertEquals(Boolean.TRUE, value);

	p = item.getItemProperty(TestData.OBSOLETE);
	assertNotNull(p);

	p = item.getItemProperty("invalid");
	assertNull(p);

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

		@Override
		public void run() {
			item.addItemProperty("invalid", null);
		}
	});

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

		@Override
		public void run() {
			item.removeItemProperty("invalid");
		}
	});

	Item item2 = PropertyBoxItem.create(box);

	p = item2.getItemProperty(TestData.ID);
	assertNotNull(p);
	assertFalse(p.isReadOnly());

}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:73,代码来源:TestItems.java

示例13: testErrors

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

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

	ApiError 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());
	}

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

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

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

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

示例14: testMatcher

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

	final CredentialsMatcher matcher = CredentialsContainer.defaultMatcher();

	final CredentialsContainer nc = new CredentialsContainer() {

		@Override
		public Object getCredentials() {
			return null;
		}
	};

	final CredentialsContainer cc = new CredentialsContainer() {

		@Override
		public Object getCredentials() {
			return "test";
		}
	};

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

		@Override
		public void run() {
			matcher.credentialsMatch(nc, cc);
		}
	});
	TestUtils.expectedException(UnexpectedCredentialsException.class, new Runnable() {

		@Override
		public void run() {
			matcher.credentialsMatch(cc, nc);
		}
	});
	TestUtils.expectedException(UnexpectedCredentialsException.class, new Runnable() {

		@Override
		public void run() {
			matcher.credentialsMatch(null, null);
		}
	});

	final CredentialsContainer cc2 = new CredentialsContainer() {

		@Override
		public Object getCredentials() {
			return "test";
		}
	};

	assertTrue(matcher.credentialsMatch(cc, cc2));

	final CredentialsContainer ncl = new CredentialsContainer() {

		@Override
		public Object getCredentials() {
			return Long.valueOf(3L);
		}
	};

	assertTrue(matcher.credentialsMatch(ncl, ncl));

	CredentialsMatcher fm = (p, s) -> p.getCredentials().equals(s.getCredentials());

	assertTrue(fm.credentialsMatch(cc, cc2));

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

示例15: testEmail

import com.holonplatform.core.internal.utils.TestUtils; //导入方法依赖的package包/类
@Test
public void testEmail() {
	Validator.email().validate("[email protected]");

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


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