use of org.junit.Assert.assertTrue in project flow by vaadin.
the class BootstrapHandlerTest method useDependencyFilters_removeDependenciesAndAddNewOnes.
@Test
public void useDependencyFilters_removeDependenciesAndAddNewOnes() throws ServiceException {
List<DependencyFilter> filters = Arrays.asList((list, context) -> {
// remove everything
list.clear();
return list;
}, (list, context) -> {
list.add(new Dependency(Dependency.Type.JAVASCRIPT, "imported-by-filter.js", LoadMode.EAGER));
list.add(new Dependency(Dependency.Type.JAVASCRIPT, "imported-by-filter2.js", LoadMode.EAGER));
return list;
}, (list, context) -> {
// removes the imported-by-filter2.js
list.remove(1);
return list;
}, (list, context) -> {
list.add(new Dependency(Dependency.Type.STYLESHEET, "imported-by-filter.css", LoadMode.EAGER));
return list;
});
service.setDependencyFilters(filters);
initUI(testUI);
BootstrapContext bootstrapContext = new BootstrapContext(request, null, session, testUI, this::contextRootRelativePath);
Document page = pageBuilder.getBootstrapPage(bootstrapContext);
Elements scripts = page.head().getElementsByTag("script");
boolean found = scripts.stream().anyMatch(element -> element.attr("src").equals("imported-by-filter.js"));
Assert.assertTrue("imported-by-filter.js should be in the head of the page", found);
found = scripts.stream().anyMatch(element -> element.attr("src").equals("imported-by-filter2.js"));
Assert.assertFalse("imported-by-filter2.js shouldn't be in the head of the page", found);
found = scripts.stream().anyMatch(element -> element.attr("src").equals("./eager.js"));
Assert.assertFalse("eager.js shouldn't be in the head of the page", found);
Elements links = page.head().getElementsByTag("link");
found = links.stream().anyMatch(element -> element.attr("href").equals("imported-by-filter.css"));
Assert.assertTrue("imported-by-filter.css should be in the head of the page", found);
}
use of org.junit.Assert.assertTrue in project flow by vaadin.
the class NodeUpdateImportsTest method noFallBackScanner_fallbackIsNotImportedEvenIfTheFileExists.
@Test
public void noFallBackScanner_fallbackIsNotImportedEvenIfTheFileExists() throws Exception {
Stream<Class<?>> classes = Stream.concat(Stream.of(NodeTestComponents.class.getDeclaredClasses()), Stream.of(ExtraNodeTestComponents.class.getDeclaredClasses()));
ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), classes.toArray(Class<?>[]::new));
// create fallback imports file:
// it is present after generated but the user is now running
// everything without fallback. The file should not be included into
// the imports
fallBackImportsFile.mkdirs();
fallBackImportsFile.createNewFile();
Assert.assertTrue(fallBackImportsFile.exists());
updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> null, tmpRoot, generatedPath, frontendDirectory, tokenFile, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {
@Override
Logger log() {
return logger;
}
};
updater.execute();
assertTrue(importsFile.exists());
String mainContent = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
// fallback file is not imported in generated-flow-imports
MatcherAssert.assertThat(mainContent, CoreMatchers.not(CoreMatchers.containsString(FrontendUtils.FALLBACK_IMPORTS_NAME)));
}
use of org.junit.Assert.assertTrue in project flow by vaadin.
the class BinderTest method invalidUsage_modifyFieldsInsideValidator_binderDoesNotThrow.
@Test
public void invalidUsage_modifyFieldsInsideValidator_binderDoesNotThrow() {
TestTextField field = new TestTextField();
AtomicBoolean validatorIsExecuted = new AtomicBoolean();
binder.forField(field).asRequired().withValidator((val, context) -> {
nameField.setValue("foo");
ageField.setValue("bar");
validatorIsExecuted.set(true);
return ValidationResult.ok();
}).bind(Person::getEmail, Person::setEmail);
binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
binder.forField(ageField).bind(Person::getLastName, Person::setLastName);
binder.setBean(new Person());
field.setValue("baz");
// mostly self control, the main check is: not exception is thrown
Assert.assertTrue(validatorIsExecuted.get());
}
use of org.junit.Assert.assertTrue in project flink by apache.
the class KinesisProxyTest method testGetShardListWithNewShardsOnSecondRun.
@Test
public void testGetShardListWithNewShardsOnSecondRun() throws Exception {
// given
List<String> shardIds = Arrays.asList(KinesisShardIdGenerator.generateFromShardOrder(0), KinesisShardIdGenerator.generateFromShardOrder(1));
String fakeStreamName = "fake-stream";
List<Shard> shards = shardIds.stream().map(shardId -> new Shard().withShardId(shardId)).collect(Collectors.toList());
AmazonKinesis mockClient = mock(AmazonKinesis.class);
KinesisProxy kinesisProxy = getProxy(mockClient);
ListShardsResult responseFirst = new ListShardsResult().withShards(shards).withNextToken(null);
doReturn(responseFirst).when(mockClient).listShards(argThat(initialListShardsRequestMatcher()));
HashMap<String, String> streamHashMap = createInitialSubscribedStreamsToLastDiscoveredShardsState(Collections.singletonList(fakeStreamName));
// when
GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);
// then
Assert.assertTrue(shardListResult.hasRetrievedShards());
Set<String> expectedStreams = new HashSet<>();
expectedStreams.add(fakeStreamName);
Assert.assertEquals(shardListResult.getStreamsWithRetrievedShards(), expectedStreams);
List<StreamShardHandle> actualShardList = shardListResult.getRetrievedShardListOfStream(fakeStreamName);
Assert.assertThat(actualShardList, hasSize(2));
List<StreamShardHandle> expectedStreamShard = IntStream.range(0, actualShardList.size()).mapToObj(i -> new StreamShardHandle(fakeStreamName, new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(i)))).collect(Collectors.toList());
Assert.assertThat(actualShardList, containsInAnyOrder(expectedStreamShard.toArray(new StreamShardHandle[actualShardList.size()])));
// given new shards
ListShardsResult responseSecond = new ListShardsResult().withShards(new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(2))).withNextToken(null);
doReturn(responseSecond).when(mockClient).listShards(argThat(initialListShardsRequestMatcher()));
// when new shards
GetShardListResult newShardListResult = kinesisProxy.getShardList(streamHashMap);
// then new shards
Assert.assertTrue(newShardListResult.hasRetrievedShards());
Assert.assertEquals(newShardListResult.getStreamsWithRetrievedShards(), expectedStreams);
List<StreamShardHandle> newActualShardList = newShardListResult.getRetrievedShardListOfStream(fakeStreamName);
Assert.assertThat(newActualShardList, hasSize(1));
List<StreamShardHandle> newExpectedStreamShard = Collections.singletonList(new StreamShardHandle(fakeStreamName, new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(2))));
Assert.assertThat(newActualShardList, containsInAnyOrder(newExpectedStreamShard.toArray(new StreamShardHandle[newActualShardList.size()])));
}
use of org.junit.Assert.assertTrue in project flink by apache.
the class JobGraphGeneratorTest method testGeneratingJobGraphWithUnconsumedResultPartition.
@Test
public void testGeneratingJobGraphWithUnconsumedResultPartition() {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple2<Long, Long>> input = env.fromElements(new Tuple2<>(1L, 2L)).setParallelism(1);
DataSet<Tuple2<Long, Long>> ds = input.map(new IdentityMapper<>()).setParallelism(3);
AbstractID intermediateDataSetID = new AbstractID();
// this output branch will be excluded.
ds.output(BlockingShuffleOutputFormat.createOutputFormat(intermediateDataSetID)).setParallelism(1);
// this is the normal output branch.
ds.output(new DiscardingOutputFormat<>()).setParallelism(1);
JobGraph jobGraph = compileJob(env);
Assert.assertEquals(3, jobGraph.getVerticesSortedTopologicallyFromSources().size());
JobVertex mapVertex = jobGraph.getVerticesSortedTopologicallyFromSources().get(1);
Assert.assertThat(mapVertex, Matchers.instanceOf(JobVertex.class));
// there are 2 output result with one of them is ResultPartitionType.BLOCKING_PERSISTENT
Assert.assertEquals(2, mapVertex.getProducedDataSets().size());
Assert.assertTrue(mapVertex.getProducedDataSets().stream().anyMatch(dataSet -> dataSet.getId().equals(new IntermediateDataSetID(intermediateDataSetID)) && dataSet.getResultType() == ResultPartitionType.BLOCKING_PERSISTENT));
}
Aggregations