本文整理汇总了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);
}
});
}
示例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));
}
示例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));
}
示例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;
}
});
}
示例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);
}
});
}
示例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();
}
});
}
示例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);
}
示例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();
}
});
}
示例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));
}
示例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));
}
示例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()));
}
示例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());
}
示例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());
}
示例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));
}
示例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"));
}