Java Code Examples for java.util.Collections.singletonMap()

The following are Jave code examples for showing how to use singletonMap() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hippo-groovy-updater   File: YamlGenerator.java   View Source Code Vote up 6 votes
/**
 * Parse file to updater node
 *
 * @param scriptClass class to use for source
 * @return Node object representing the groovy updater to marshall to xml
 */
public static Map<String, Map<String, Object>> getUpdateYamlScript(final ScriptClass scriptClass) {
    final Updater updater = scriptClass.getUpdater();

    Map<String, Object> properties = new LinkedHashMap<>();
    addNotEmptyProperty(JCR_PRIMARY_TYPE, HIPPOSYS_UPDATERINFO, properties);

    addNotEmptyProperty(HIPPOSYS_BATCHSIZE, updater.batchSize(), properties);
    addNotEmptyProperty(HIPPOSYS_DESCRIPTION, updater.description(), properties);
    addNotEmptyProperty(HIPPOSYS_DRYRUN, updater.dryRun(), properties);
    addNotEmptyProperty(HIPPOSYS_PARAMETERS, updater.parameters(), properties);
    if (StringUtils.isBlank(updater.xpath())) {
        addNotEmptyProperty(HIPPOSYS_PATH, updater.path(), properties);
    }
    addNotEmptyProperty(HIPPOSYS_QUERY, updater.xpath(), properties);
    addNotEmptyProperty(HIPPOSYS_SCRIPT, removeEmptyIndents(scriptClass.getContent()), properties);
    addNotEmptyProperty(HIPPOSYS_THROTTLE, updater.throttle(), properties);
    return Collections.singletonMap(getBootstrapPath(scriptClass), properties);
}
 
Example 2
Project: incubator-netbeans   File: MatcherTest.java   View Source Code Vote up 6 votes
public void testReferencedInNoNPEForMissingTrees() throws Exception {
    String code = "package test; public class Test { private void test() { | if (true) System.err.println(); } private int a^aa;}";
    int pos = code.indexOf("|");
    
    code = code.replaceAll(Pattern.quote("|"), "");

    int varpos = code.indexOf("^");
    
    code = code.replaceAll(Pattern.quote("^"), "");

    prepareTest("test/Test.java", code);

    TreePath tp = info.getTreeUtilities().pathFor(pos);
    TreePath var = info.getTreeUtilities().pathFor(varpos);
    Map<String, TreePath> variables = Collections.singletonMap("$1", var);
    Map<String, Collection<? extends TreePath>> multiVariables = Collections.<String, Collection<? extends TreePath>>singletonMap("$2$", Arrays.asList(tp));
    Map<String, String> variables2Names = Collections.emptyMap();
    Context ctx = new Context(SPIAccessor.getINSTANCE().createHintContext(info, HintsSettings.getGlobalSettings(), null, null, variables, multiVariables, variables2Names));

    new Matcher(ctx).referencedIn(new Variable("$1"), new Variable("$2$"));
}
 
Example 3
Project: cyberduck   File: MoveWorkerTest.java   View Source Code Vote up 6 votes
@Test
public void testMoveSameFolderCryptomator() throws Exception {
    final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(
        System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password")
    ));
    final FTPSession session = new FTPSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new DefaultHomeFinderService(session).find();
    final Path vault = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    new CryptoTouchFeature<Integer>(session, new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))), new FTPWriteFeature(session), cryptomator).touch(source, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    final MoveWorker worker = new MoveWorker(Collections.singletonMap(source, target), PathCache.empty(), PasswordStoreFactory.get(), new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledProgressListener(), new DisabledTranscriptListener());
    worker.run(session);
    assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
    new CryptoDeleteFeature(session, new FTPDeleteFeature(session), cryptomator).delete(Arrays.asList(target, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
Example 4
Project: GitHub   File: RequestBuilderTest.java   View Source Code Vote up 6 votes
@Test public void queryParamMapsConvertedToNullShouldError() throws Exception {
  class Example {
    @GET("/query") Call<ResponseBody> queryPath(@QueryMap Map<String, String> a) {
      return null;
    }
  }

  Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
      .baseUrl("http://example.com")
      .addConverterFactory(new NullObjectConverterFactory());

  Map<String, String> queryMap = Collections.singletonMap("kit", "kat");

  try {
    buildRequest(Example.class, retrofitBuilder, queryMap);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessageContaining(
        "Query map value 'kat' converted to null by retrofit2.helpers.NullObjectConverterFactory$1 for key 'kit'.");
  }
}
 
Example 5
Project: alfresco-remote-api   File: AbstractBaseApiTest.java   View Source Code Vote up 5 votes
protected void deleteNode(String nodeId, boolean permanent, int expectedStatus) throws Exception
{
    Map params = null;
    if (permanent == true)
    {
        params = Collections.singletonMap("permanent", "true");
    }
    
    delete(URL_NODES, nodeId, params, expectedStatus);
}
 
Example 6
Project: cyberduck   File: MoveWorkerTest.java   View Source Code Vote up 5 votes
@Test
public void testMoveSameFolderCryptomator() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path vault = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final byte[] content = RandomUtils.nextBytes(40500);
    final TransferStatus status = new TransferStatus();
    new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new S3DefaultDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new S3MultipartWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    final MoveWorker worker = new MoveWorker(Collections.singletonMap(source, target), PathCache.empty(), PasswordStoreFactory.get(), new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledProgressListener(), new DisabledTranscriptListener());
    worker.run(session);
    assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
    final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
    assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
    assertArrayEquals(content, out.toByteArray());
    new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator).delete(Arrays.asList(target, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
Example 7
Project: cyberduck   File: CopyWorkerTest.java   View Source Code Vote up 5 votes
@Test
public void testCopyFileOutsideVault() throws Exception {
    final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials(
            System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key")
    ));
    final AzureSession session = new AzureSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path clearFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    new AzureDirectoryFeature(session, null).mkdir(clearFolder, null, new TransferStatus());
    final Path encryptedFolder = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path encryptedFile = new Path(encryptedFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    new CryptoDirectoryFeature<Void>(session, new AzureDirectoryFeature(session, null), new AzureWriteFeature(session, null), cryptomator).mkdir(encryptedFolder, null, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(encryptedFolder));
    new CryptoTouchFeature<Void>(session, new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new AzureWriteFeature(session, null))), new AzureWriteFeature(session, null), cryptomator).touch(encryptedFile, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(encryptedFile));
    // move file outside vault
    final Path cleartextFile = new Path(clearFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(encryptedFile, cleartextFile), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new AzureFindFeature(session, null), cryptomator).find(encryptedFile));
    assertTrue(new AzureFindFeature(session, null).find(cleartextFile));
    registry.clear();
    new DeleteWorker(new DisabledLoginCallback(), Arrays.asList(vault, clearFolder), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
 
Example 8
Project: cyberduck   File: CopyWorkerTest.java   View Source Code Vote up 5 votes
@Test
public void testCopyFile() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(
            System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password")
    ));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    final byte[] content = RandomUtils.nextBytes(40500);
    final TransferStatus status = new TransferStatus();
    new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new SFTPDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertEquals(content.length, new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(source).getSize());
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(target));
    final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
    assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
    assertArrayEquals(content, out.toByteArray());
    new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
 
Example 9
Project: cyberduck   File: CopyWorkerTest.java   View Source Code Vote up 5 votes
@Test
public void testCopyToDifferentFolderLongFilenameCryptomator() throws Exception {
    final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials(
            System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key")
    ));
    final AzureSession session = new AzureSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final CryptoVault cryptomator = new CryptoVault(new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new DisabledPasswordStore());
    final Path vault = cryptomator.create(session, null, new VaultCredentials("test"));
    final Path source = new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.file));
    final Path targetFolder = new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.directory));
    final Path target = new Path(targetFolder, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.file));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    new CryptoTouchFeature<Void>(session, new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new AzureWriteFeature(session, null))), new AzureWriteFeature(session, null), cryptomator).touch(source, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    new CryptoDirectoryFeature<Void>(session, new AzureDirectoryFeature(session, null), new AzureWriteFeature(session, null), cryptomator).mkdir(targetFolder, null, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(targetFolder));
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
    registry.clear();
    new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
 
Example 10
Project: incubator-netbeans   File: SequentialPropertyEvaluatorTest.java   View Source Code Vote up 5 votes
public void testEvaluate() throws Exception {
    // XXX check override order, property name evaluation, $$ escaping, bare or final $,
    // cyclic errors, undef'd property substitution, no substs in predefs, etc.
    Map<String,String> m1 = Collections.singletonMap("y", "val");
    Map<String,String> m2 = new HashMap<String,String>();
    m2.put("x", "${y}");
    m2.put("y", "y-${x}");
    List<Map<String,String>> m1m2 = new ArrayList<Map<String,String>>();
    m1m2.add(m1);
    m1m2.add(m2);
    assertEquals("x evaluates to former y", "val", evaluate("x", Collections.<String,String>emptyMap(), m1m2));
    assertEquals("first y defines it", "val", evaluate("y", Collections.<String,String>emptyMap(), m1m2));
    assertEquals("circularity error", null, evaluate("x", Collections.<String,String>emptyMap(), Collections.singletonList(m2)));
    assertEquals("circularity error", null, evaluate("y", Collections.<String,String>emptyMap(), Collections.singletonList(m2)));
    m2.clear();
    m2.put("y", "yval_${z}");
    m2.put("x", "xval_${y}");
    m2.put("z", "zval");
    Map<String,String> all = evaluateAll(Collections.<String,String>emptyMap(), Collections.singletonList(m2));
    assertNotNull("no circularity error", all);
    assertEquals("have three properties", 3, all.size());
    assertEquals("double substitution", "xval_yval_zval", all.get("x"));
    assertEquals("single substitution", "yval_zval", all.get("y"));
    assertEquals("no substitution", "zval", all.get("z"));
    // Yuck. But it failed once, so check it now.
    Properties p = new Properties();
    p.load(new ByteArrayInputStream("project.mylib=../mylib\njavac.classpath=${project.mylib}/build/mylib.jar\nrun.classpath=${javac.classpath}:build/classes".getBytes("US-ASCII")));
    all = evaluateAll(Collections.<String,String>emptyMap(), Collections.singletonList(NbCollections.checkedMapByFilter(p, String.class, String.class, true)));
    assertNotNull("no circularity error", all);
    assertEquals("javac.classpath correctly substituted", "../mylib/build/mylib.jar", all.get("javac.classpath"));
    assertEquals("run.classpath correctly substituted", "../mylib/build/mylib.jar:build/classes", all.get("run.classpath"));
}
 
Example 11
Project: traccar-service   File: MaintenanceEventHandler.java   View Source Code Vote up 5 votes
@Override
protected Map<Event, Position> analyzePosition(Position position) {
    Device device = Context.getIdentityManager().getById(position.getDeviceId());
    if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
        return null;
    }

    double maintenanceInterval = Context.getDeviceManager()
            .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0, false);
    if (maintenanceInterval == 0) {
        return null;
    }
    double maintenanceStart = Context.getDeviceManager()
            .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false);

    double oldTotalDistance = 0.0;
    double newTotalDistance = 0.0;

    Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
    if (lastPosition != null) {
        oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
    }
    newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE);

    oldTotalDistance -= maintenanceStart;
    newTotalDistance -= maintenanceStart;

    if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
        Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
        event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance);
        return Collections.singletonMap(event, position);
    }

    return null;
}
 
Example 12
Project: cyberduck   File: CopyWorkerTest.java   View Source Code Vote up 5 votes
@Test
public void testCopyToDifferentFolderCryptomator() throws Exception {
    final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(
            System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password")
    ));
    final FTPSession session = new FTPSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new DefaultHomeFinderService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path targetFolder = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path target = new Path(targetFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    new CryptoTouchFeature<Integer>(session, new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))), new FTPWriteFeature(session), cryptomator).touch(source, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    new CryptoDirectoryFeature<Integer>(session, new FTPDirectoryFeature(session), new FTPWriteFeature(session), cryptomator).mkdir(targetFolder, null, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(targetFolder));
    final FTPSession copySession = new FTPSession(host);
    copySession.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    copySession.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(copySession, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
    registry.clear();
    new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
 
Example 13
Project: alfresco-repository   File: BaseNodeServiceTest.java   View Source Code Vote up 4 votes
public void testAspectWithChildAssociationsCreationAndRetrieval() throws Exception
{
    // Create a folder.  This is like the user's home folder, say.
    NodeRef folderNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(BaseNodeServiceTest.NAMESPACE, "UserX-" + GUID.generate()),
            ContentModel.TYPE_FOLDER).getChildRef();
    // Create a document.  This is the actual document uploaded by the user.
    NodeRef fileNodeRef = nodeService.createNode(
            folderNodeRef,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(BaseNodeServiceTest.NAMESPACE, "Uploaded.pdf"),
            ContentModel.TYPE_FOLDER).getChildRef();
    // So, thus far, this is exactly what you have.  Now for the bit to add some renditions.
    // First, we can make some content data pages - spoofed, of course
    List<ContentData> renditionContentPages = new ArrayList<ContentData>(20);
    // This loop is where you will, outside of the transaction, push the page content into the repo
    for(int i = 0; i < 100; i++)
    {
        ContentData contentData = new ContentData(null, MimetypeMap.MIMETYPE_PDF, 10245, "UTF-8");
        renditionContentPages.add(contentData);
    }
    
    nodeService.addAspect(fileNodeRef, ASPECT_QNAME_TEST_RENDERED, null);
    int pageNumber = 0;
    for (ContentData renditionContentPage : renditionContentPages)
    {
        pageNumber++;
        QName renditionQName = makePageAssocName(pageNumber);
        Map<QName, Serializable> properties = Collections.singletonMap(
                PROP_QNAME_TEST_RENDITION_PAGE_CONTENT,
                (Serializable) renditionContentPage);
        nodeService.createNode(
                fileNodeRef,
                ASSOC_TYPE_QNAME_TEST_RENDITION,
                renditionQName,
                TYPE_QNAME_TEST_RENDITION_PAGE,
                properties);
    }
    
    // That's it for uploading.  Now we retrieve them.
    if (!nodeService.hasAspect(fileNodeRef, ASPECT_QNAME_TEST_RENDERED))
    {
        // Jump to the original rendition retrieval code
        return;
    }
    // It has the aspect, so it's the new model
    List<ChildAssociationRef> fetchedRenditionChildAssocs = nodeService.getChildAssocs(
            fileNodeRef,
            ASSOC_TYPE_QNAME_TEST_RENDITION,
            RegexQNamePattern.MATCH_ALL);
    assertEquals(
            "We didn't get the correct number of pages back",
            renditionContentPages.size(),
            fetchedRenditionChildAssocs.size());
    // Get page ... 5.  This is to prove that they are ordered.
    ChildAssociationRef fetchedRenditionChildAssoc5 = fetchedRenditionChildAssocs.get(4);
    QName page5QName = makePageAssocName(5);
    assertEquals(
            "Local name of page 5 assoc is not correct",
            page5QName,
            fetchedRenditionChildAssoc5.getQName());
    // Now retrieve page 5 using the NodeService
    List<ChildAssociationRef> fetchedRenditionChildAssocsPage5 = nodeService.getChildAssocs(
            fileNodeRef,
            ASSOC_TYPE_QNAME_TEST_RENDITION,
            page5QName);
    assertEquals("Expected exactly one result", 1, fetchedRenditionChildAssocsPage5.size());
    assertEquals("Targeted page retrieval was not correct",
            page5QName,
            fetchedRenditionChildAssocsPage5.get(0).getQName());
}
 
Example 14
Project: kafka-0.11.0.0-src-with-comment   File: ConsumerCoordinatorTest.java   View Source Code Vote up 4 votes
@Test
public void testPatternJoinGroupLeader() {
    final String consumerId = "leader";

    subscriptions.subscribe(Pattern.compile("test.*"), rebalanceListener);

    // partially update the metadata with one topic first,
    // let the leader to refresh metadata during assignment
    metadata.setTopics(singletonList(topic1));
    metadata.update(TestUtils.singletonCluster(topic1, 1), Collections.<String>emptySet(), time.milliseconds());

    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady();

    // normal join group
    Map<String, List<String>> memberSubscriptions = Collections.singletonMap(consumerId, singletonList(topic1));
    partitionAssignor.prepare(Collections.singletonMap(consumerId, Arrays.asList(t1p, t2p)));

    client.prepareResponse(joinGroupLeaderResponse(1, consumerId, memberSubscriptions, Errors.NONE));
    client.prepareResponse(new MockClient.RequestMatcher() {
        @Override
        public boolean matches(AbstractRequest body) {
            SyncGroupRequest sync = (SyncGroupRequest) body;
            return sync.memberId().equals(consumerId) &&
                    sync.generationId() == 1 &&
                    sync.groupAssignment().containsKey(consumerId);
        }
    }, syncGroupResponse(Arrays.asList(t1p, t2p), Errors.NONE));
    // expect client to force updating the metadata, if yes gives it both topics
    client.prepareMetadataUpdate(cluster, Collections.<String>emptySet());

    coordinator.poll(time.milliseconds(), Long.MAX_VALUE);

    assertFalse(coordinator.needRejoin());
    assertEquals(2, subscriptions.assignedPartitions().size());
    assertEquals(2, subscriptions.groupSubscription().size());
    assertEquals(2, subscriptions.subscription().size());
    assertEquals(1, rebalanceListener.revokedCount);
    assertEquals(Collections.emptySet(), rebalanceListener.revoked);
    assertEquals(1, rebalanceListener.assignedCount);
    assertEquals(2, rebalanceListener.assigned.size());
}
 
Example 15
Project: swblocks-decisiontree   File: ChangeSetTest.java   View Source Code Vote up 4 votes
@Test
public void testConstruction() {
    final Set<RuleChange> ruleChanges = new HashSet<>(1);

    final Instant start = NOW.minus(Period.ofWeeks(-1));
    final Instant end = start.plus(Period.ofWeeks(5));
    final DateRange range = new DateRange(start, end);
    final InputDriver[] drivers = getInputDriverArray("Test1", "Test2", "Test3");
    final Map<String, String> outputs = Collections.singletonMap("outputDriver", "result");
    final DecisionTreeRule rule =
            new DecisionTreeRule(new UUID(0, 1), new UUID(0, 2), drivers, outputs, start, end);
    final RuleChange ruleChange = new RuleChange(Type.NEW, rule);

    ruleChanges.add(ruleChange);

    final Set<ValueGroupChange> valueGroupChanges = new HashSet<>(1);
    final List<String> valueGroupDrivers = getValueGroupsDrivers("Test1", "Test2", "Test3");
    final ValueGroup valueGroup = new ValueGroup(new UUID(0, 1), "TestValueGroup", valueGroupDrivers,
            range);
    final ValueGroupChange valueGroupChange =
            new ValueGroupChange(Type.NEW, valueGroup);

    valueGroupChanges.add(valueGroupChange);

    final Instant initiatorTime = NOW;
    final Instant authoriserTime = initiatorTime.plus(Period.ofWeeks(1));

    final Audit audit = new Audit("User1", initiatorTime, "User2", authoriserTime);
    final Change change = new Change(INITIAL_CHANGE_ID, "TEST-RULESET", NOW, CHANGE_RANGE, audit, ruleChanges,
            valueGroupChanges);

    final Set<Change> changes = new HashSet<>(1);
    changes.add(change);

    final UUID uuid = new UUID(0, 3);
    final ChangeSet changeSet = new ChangeSet(uuid, "changeset-name", changes);
    setBean(changeSet);

    this.injectedValues.put("id", uuid);
    this.injectedValues.put("name", "changeset-name");
    this.injectedValues.put("changes", changes);

    JblTestClassUtils.assertGetterCorrectForConstructorInjection(this.injectedValues, getBean());
}
 
Example 16
Project: incubator-netbeans   File: DataModel.java   View Source Code Vote up 4 votes
private CreatedModifiedFiles regenerate () {
    if (cmf == null) {
        cmf = new CreatedModifiedFiles (getProject ());
    }

    boolean newAPI = true;
    try {
        newAPI = getModuleInfo().getDependencyVersion(AUTOUPDATE_MODULE_NEW) != null;
    } catch (IOException x) {
        Logger.getLogger(DataModel.class.getName()).log(Level.INFO, null, x);
    }
    String extension = (newAPI) ? AUTOUPDATE_INSTANCE_TYPE_EXT : AUTOUPDATE_SETTINGS_TYPE_EXT;
    FileObject template = newAPI ? null : CreatedModifiedFiles.getTemplate("update_center.xml"); // NOI18N
    String serviceTypeName = getModuleInfo().getCodeNameBase ().replace ('.', '_') + AUTOUPDATE_SERVICE_TYPE; // NOI18N
    FileSystem layer = LayerHandle.forProject (getProject ()).layer (false);
    
    String pathToAutoUpdateType = AUTOUPDATE_TYPES + '/' + serviceTypeName + '.' + extension;
    int sequence = 0;
    if (layer != null) {
        FileObject f;
        do {
            f = layer.findResource (pathToAutoUpdateType);
            if (f != null) {
                pathToAutoUpdateType = AUTOUPDATE_TYPES + '/' + serviceTypeName + '_' + ++sequence + '.' + extension;
            }
        } while (f != null);
    }
    String codename = null;
    NbModuleProvider mp = getProject().getLookup().lookup(NbModuleProvider.class);
    Manifest mani = Util.getManifest(mp.getManifestFile());
    if (mani != null) {
        codename = mani.getMainAttributes().getValue("OpenIDE-Module"); // NOI18N
    }
    if (codename == null) {
        codename = getModuleInfo().getCodeNameBase();
    }
    final Map<String, String> substitutionTokens = newAPI ? null : Collections.singletonMap("MODULECODENAME", codename);        
    cmf.add(cmf.createLayerEntry(pathToAutoUpdateType, template, substitutionTokens, null, null)); // NOI18N
    
    if (newAPI) {
        cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, "instanceCreate", "methodvalue:org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogFactory.createUpdateProvider")); //NOI18N
        cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, "instanceOf", "org.netbeans.spi.autoupdate.UpdateProvider")); //NOI18N            
    }        
    String url_key_base = getModuleInfo().getCodeNameBase ().replace ('.', '_') + AUTOUPDATE_SERVICE_TYPE; //NOI18N
    String url_key = sequence == 0 ? url_key_base : url_key_base + '_' + sequence; // NOI18N
    cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, "enabled", Boolean.TRUE)); //NOI18N
    
    // write into bundle
    ManifestManager mm = ManifestManager.getInstance(Util.getManifest(getModuleInfo().getManifestFile()), false);
    String localizingBundle = mm.getLocalizingBundle ();
    localizingBundle = localizingBundle.substring (0, localizingBundle.indexOf ('.'));
    localizingBundle = localizingBundle.replace ('/', '.');
    cmf.add (cmf.createLayerAttribute (pathToAutoUpdateType, 
            "displayName", "bundlevalue:" + localizingBundle + "#" + pathToAutoUpdateType));
    cmf.add(cmf.createLayerAttribute(pathToAutoUpdateType, "url", "bundlevalue:" + localizingBundle + "#" + url_key)); //NOI18N
    
    cmf.add (cmf.bundleKeyDefaultBundle (pathToAutoUpdateType, ucDisplayName));
    cmf.add (cmf.bundleKeyDefaultBundle (url_key, ucUrl));
    
    // add dependency to autoupdate module
    cmf.add(cmf.addModuleDependency(newAPI ? AUTOUPDATE_MODULE_NEW : AUTOUPDATE_MODULE, null, null, false));
    
    return cmf;
}
 
Example 17
Project: lams   File: AllowedMethodsHandler.java   View Source Code Vote up 4 votes
@Override
public Map<String, Class<?>> parameters() {
    return Collections.<String, Class<?>>singletonMap("methods", String[].class);
}
 
Example 18
Project: lams   File: SessionImpl.java   View Source Code Vote up 4 votes
private Map<String, Object> getNaturalIdParameters(Object naturalIdValue) {
	return Collections.singletonMap( naturalIdAttributeName, naturalIdValue );
}
 
Example 19
Project: openjdk-jdk10   File: java_util_Collections_EmptyMap.java   View Source Code Vote up 4 votes
protected Map<String, String> getAnotherObject() {
    return Collections.singletonMap("key", "value");
}
 
Example 20
Project: light-tram-4j   File: SingleValuePlaceholderValueProvider.java   View Source Code Vote up 4 votes
@Override
public Map<String, String> getParams() {
  return Collections.singletonMap("singleValue", pathParam.toString());
}