/** * A shortcut to the frequently used <code>not(nullValue())</code>. * <p/> * For example: * <pre>assertThat(cheese, is(notNullValue()))</pre> * instead of: * <pre>assertThat(cheese, is(not(nullValue())))</pre> */ public static org.hamcrest.Matcher<java.lang.Object> notNullValue() { return org.hamcrest.core.IsNull.notNullValue(); }
/** * Creates a matcher that matches if examined object is <code>null</code>. * <p/> * For example: * <pre>assertThat(cheese, is(nullValue())</pre> */ public static org.hamcrest.Matcher<java.lang.Object> nullValue() { return org.hamcrest.core.IsNull.nullValue(); }
/** * Creates a matcher that matches if examined object is <code>null</code>. * For example: * <pre>assertThat(cheese, is(nullValue())</pre> * */ public static Matcher<Object> nullValue() { return new IsNull<Object>(); }
@Test public void testTryWriteLockFailingClosesEntity() throws Exception { when(client.tryLock(WRITE)).thenReturn(false); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); assertThat(lock.tryWriteLock(), nullValue()); verify(client).close(); }
@Test public void shouldParseDynamicOperandFromStringContainingReferenceValueOfSelector() { DynamicOperand operand = parser.parseDynamicOperand(tokens("REFERENCE(tableA)"), typeSystem, mock(Source.class)); assertThat(operand, is(instanceOf(ReferenceValue.class))); ReferenceValue value = (ReferenceValue)operand; assertThat(value.selectorName(), is(selectorName("tableA"))); assertThat(value.getPropertyName(), is(nullValue())); }
@Test public void testTryReadLockTryLocksRead() throws Exception { when(client.tryLock(READ)).thenReturn(true); when(entityRef.fetchEntity(null)).thenReturn(client); when(connection.<VoltronReadWriteLockClient, Void, Void>getEntityRef(VoltronReadWriteLockClient.class, 1, "VoltronReadWriteLock-TestLock")).thenReturn(entityRef); VoltronReadWriteLock lock = new VoltronReadWriteLock(connection, "TestLock"); assertThat(lock.tryReadLock(), notNullValue()); verify(client).tryLock(READ); }
@Test public void nullDeploymentClassLoaderAfterDispose() { ApplicationDescriptor descriptor = mock(ApplicationDescriptor.class); when(descriptor.getConfigResources()).thenReturn(emptySet()); DefaultMuleApplication application = new DefaultMuleApplication(descriptor, mock(MuleApplicationClassLoader.class), emptyList(), null, null, null, appLocation, null, null, null); application.install(); assertThat(application.deploymentClassLoader, is(notNullValue())); application.dispose(); assertThat(application.deploymentClassLoader, is(nullValue())); }
@Test public void transformerFactoryProperties() { SetPropertyAnswer setPropertyAnswer = new SetPropertyAnswer(transformerFactory); doAnswer(setPropertyAnswer).when(transformerFactoryWrapper).setAttribute(anyString(), anyObject()); defaultXMLSecureFactories.configureTransformerFactory(transformerFactoryWrapper); assertThat(setPropertyAnswer.exception, is(nullValue())); for (String property : FACTORY_ATTRIBUTES) { verify(transformerFactoryWrapper).setAttribute(property, ""); } }
@Test public void testGetAllWithLoaderException() throws Exception { when(cacheLoaderWriter.loadAll(ArgumentMatchers.<Iterable<Number>>any())).thenAnswer(invocation -> { @SuppressWarnings("unchecked") Iterable<Integer> iterable = (Iterable<Integer>) invocation.getArguments()[0]; fail("expected BulkCacheLoadingException"); } catch (BulkCacheLoadingException ex) { assertThat(ex.getFailures().size(), is(1)); assertThat(ex.getFailures().get(2), is(notNullValue())); assertThat(ex.getSuccesses().size(), is(lessThan(4))); assertThat(ex.getSuccesses().containsKey(2), is(false));
@Test public void testActionBeginOrJoinAndNoTx() throws Exception { MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_BEGIN_OR_JOIN); ExecutionTemplate executionTemplate = createExecutionTemplate(config); config.setFactory(new TestTransactionFactory(mockTransaction)); Object result = executionTemplate.execute(getEmptyTransactionCallback()); assertThat(result, is(RETURN_VALUE)); verify(mockTransaction).commit(); verify(mockTransaction, never()).rollback(); assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue()); }
@Test public void shouldImportIntoWorkspaceTheDocumentViewOfTheContentUsedInTckTests() throws Exception { Session session3 = repository.login(); session.nodeTypeManager().registerNodeTypes(resourceStream("tck/tck_test_types.cnd"), true); session.getWorkspace().importXML("/", resourceStream("tck/documentViewForTckTests.xml"), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); assertThat(session.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session.getNode("/testroot/workarea"), is(notNullValue())); assertNode("/testroot/workarea"); Session session1 = repository.login(); assertThat(session1.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session1.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session1.getNode("/testroot/workarea"), is(notNullValue())); session1.logout(); assertThat(session3.getRootNode().hasNode("testroot/workarea"), is(true)); assertThat(session3.getRootNode().getNode("testroot/workarea"), is(notNullValue())); assertThat(session3.getNode("/testroot/workarea"), is(notNullValue())); session3.logout(); }
@SuppressWarnings( "deprecation" ) public void testShouldCreateProperVersionHistoryWhenSavingVersionedNode() throws Exception { session = getHelper().getReadWriteSession(); Node node = session.getRootNode().addNode("test", "nt:unstructured"); node.addMixin("mix:versionable"); session.save(); assertThat(node.hasProperty("jcr:isCheckedOut"), is(true)); assertThat(node.getProperty("jcr:isCheckedOut").getBoolean(), is(true)); assertThat(node.hasProperty("jcr:versionHistory"), is(true)); Node history = node.getProperty("jcr:versionHistory").getNode(); assertThat(history, is(notNullValue())); assertThat(node.hasProperty("jcr:baseVersion"), is(true)); Node version = node.getProperty("jcr:baseVersion").getNode(); assertThat(version, is(notNullValue())); assertThat(version.getParent(), is(history)); assertThat(node.hasProperty("jcr:uuid"), is(true)); assertThat(node.getProperty("jcr:uuid").getString(), is(history.getProperty("jcr:versionableUuid").getString())); assertThat(versionHistory(node).getUUID(), is(history.getUUID())); assertThat(versionHistory(node).getIdentifier(), is(history.getIdentifier())); assertThat(versionHistory(node).getPath(), is(history.getPath())); assertThat(baseVersion(node).getUUID(), is(version.getUUID())); assertThat(baseVersion(node).getIdentifier(), is(version.getIdentifier())); assertThat(baseVersion(node).getPath(), is(version.getPath())); }
@FixFor( "MODE-1089" ) public void testShouldNotFailGettingVersionHistoryForNodeMadeVersionableSinceLastSave() throws Exception { Session session1 = getHelper().getSuperuserSession(); VersionManager vm = session1.getWorkspace().getVersionManager(); // Create node structure Node root = session1.getRootNode(); Node area = root.addNode("tmp2", "nt:unstructured"); Node outer = area.addNode("outerFolder"); Node inner = outer.addNode("innerFolder"); Node file = inner.addNode("testFile.dat"); file.setProperty("jcr:mimeType", "text/plain"); file.setProperty("jcr:data", "Original content"); session1.save(); file.addMixin("mix:versionable"); // session.save(); isVersionable(vm, file); // here's the problem session1.save(); Version v1 = vm.checkin(file.getPath()); assertThat(v1, is(notNullValue())); // System.out.println("Created version: " + v1); // ubgraph(root.getNode("jcr:system/jcr:versionStorage")); }
@Test public void shouldFindMasterBranchAsPrimaryItemUnderTreeNode() throws Exception { Node git = gitRemoteNode(); Node tree = git.getNode("tree"); Item primaryItem = tree.getPrimaryItem(); assertThat(primaryItem, is(notNullValue())); assertThat(primaryItem, is(instanceOf(Node.class))); Node primaryNode = (Node)primaryItem; assertThat(primaryNode.getName(), is("master")); assertThat(primaryNode.getParent(), is(sameInstance(tree))); assertThat(primaryNode, is(sameInstance(tree.getNode("master")))); }
protected static void importContent( Node parent, String resourceName, int uuidBehavior ) throws RepositoryException, IOException { InputStream stream = resourceStream(resourceName); assertThat(stream, is(notNullValue())); parent.getSession().getWorkspace().importXML(parent.getPath(), stream, uuidBehavior); }
@Test public void shouldStartRepositoryUsingLocalEnvironmentWithDefaultPersistenceConfiguration() throws Exception { // Create the repository configuration ... String configFilePath = "config/repo-config-inmemory-no-persistence.json"; InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configFilePath); RepositoryConfiguration repositoryConfiguration = RepositoryConfiguration.read(configFileStream, "doesn't matter"); LocalEnvironment environment = new LocalEnvironment(); repositoryConfiguration = repositoryConfiguration.with(environment); // Start the engine and repository ... ModeShapeEngine engine = new ModeShapeEngine(); engine.start(); try { JcrRepository repository = engine.deploy(repositoryConfiguration); Session session = repository.login(); Node root = session.getRootNode(); root.addNode("Library", "nt:folder"); session.save(); session.logout(); session = repository.login(); Node library = session.getNode("/Library"); assertThat(library, is(notNullValue())); assertThat(library.getPrimaryNodeType().getName(), is("nt:folder")); session.logout(); } finally { engine.shutdown().get(); environment.shutdown(); } }
@Test public void shouldSerializeMapWithSimpleTypes() throws Exception { MapRepresentation rep = new MapRepresentation( map( "nulls", null, "strings", "a string", "numbers", 42, "booleans", true ) ); OutputFormat format = new OutputFormat( new JsonFormat(), new URI( "http://localhost/" ), null ); String serializedMap = format.assemble( rep ); Map<String, Object> map = JsonHelper.jsonToMap( serializedMap ); assertThat( map.get( "nulls" ), is( nullValue() ) ); assertThat( map.get( "strings" ), is( "a string" ) ); assertThat( map.get( "numbers" ), is( 42 ) ); assertThat( map.get( "booleans" ), is( true ) ); }
@Test public void testTransactionalState() throws Exception { boolean shouldThrowException = resultMap.get(hasTransactionInContext).get(transactionConfig); Exception thrownException = null; CoreEvent result = null; if (hasTransactionInContext) { TransactionCoordination.getInstance().bindTransaction(mockTransaction); } ValidateTransactionalStateInterceptor<CoreEvent> interceptor = new ValidateTransactionalStateInterceptor<>(new ExecuteCallbackInterceptor<CoreEvent>(), transactionConfig, false); try { result = interceptor.execute(() -> mockMuleEvent, new ExecutionContext()); } catch (IllegalTransactionStateException e) { thrownException = e; } if (shouldThrowException) { assertThat(thrownException, notNullValue()); assertThat(thrownException, instanceOf(IllegalTransactionStateException.class)); } else { assertThat(result, is(mockMuleEvent)); } } }
@FixFor( "MODE-701" ) public void testShouldBeAbleToImportAutocreatedChildNodeWithoutDuplication() throws Exception { session = getHelper().getSuperuserSession(); /* * Add a node that would satisfy the constraint */ Node root = getTestRoot(session); Node parentNode = root.addNode("autocreatedChildRoot", "nt:unstructured"); session.save(); Node targetNode = parentNode.addNode("nodeWithAutocreatedChild", "modetest:nodeWithAutocreatedChild"); assertThat(targetNode.getNode("modetest:autocreatedChild"), is(notNullValue())); // Don't save this yet session.refresh(false); InputStream in = getClass().getResourceAsStream("/io/autocreated-node-test.xml"); session.importXML(root.getPath() + "/autocreatedChildRoot", in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testRemoveAllWithWriterException() throws Exception { doAnswer(invocation -> { Iterable<Integer> iterable = (Iterable) invocation.getArguments()[0]; Set<Integer> result = new HashSet<>(); fail("expected CacheWritingException"); } catch (BulkCacheWritingException ex) { assertThat(ex.getFailures().size(), is(1)); assertThat(ex.getFailures().get(2), is(notNullValue())); assertThat(ex.getSuccesses().size(), is(3)); assertThat(ex.getSuccesses().containsAll(Arrays.asList(1, 3, 4)), is(true));