Java源码示例:org.eclipse.collections.impl.factory.Sets

示例1
@Test
public void testComboInFullPredicate() {
    Predicate<ChangeKey> singleComboPredicate1 =
            ChangeKeyPredicateBuilder.parseFullPredicate("sc%1~%~objA,mytableC~%");
    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjCChng1),
            allChanges.select(singleComboPredicate1).toSet());

    Predicate<ChangeKey> pred2 =
            ChangeKeyPredicateBuilder.parseFullPredicate("%~%~%~CCCC%");
    assertEquals(Sets.mutable.with(tableSch1ObjBChng1, tableSch2ObjAChng1),
            allChanges.select(pred2).toSet());

    Predicate<ChangeKey> fullComboPredicate =
            ChangeKeyPredicateBuilder.parseFullPredicate("sc%1~%~objA,mytableC~%;%~%~%~CCCC%");
    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjCChng1, tableSch1ObjBChng1, tableSch2ObjAChng1),
            allChanges.select(fullComboPredicate).toSet());
}
 
示例2
@Test
public void testSchema() {
    Predicate<ChangeKey> allSchemaPredicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("sch%");
    assertEquals(allChanges.toSet(),
            allChanges.select(allSchemaPredicate).toSet());

    Predicate<ChangeKey> schema1Predicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("sch1%~%~%~%");

    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjBChng1, tableSch1ObjCChng1, viewSch1ObjD, viewSch1ObjE),
            allChanges.select(schema1Predicate).toSet());

    Predicate<ChangeKey> schema2Predicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("%2~%~%~%");

    assertEquals(Sets.mutable.with(tableSch2ObjAChng1, viewSch2ObjF),
            allChanges.select(schema2Predicate).toSet());
}
 
示例3
private ChecksumEntryInclusionPredicate createLookupIndexForObjectType(DbEnvironment env, ImmutableList<Change> sourceChanges, final String changeTypeName) {
    LookupIndex objectTypeIndex = new LookupIndex(Sets.immutable.with(changeTypeName));
    ImmutableList<Change> objectTypeChanges = sourceChanges.select(new Predicate<Change>() {
        @Override
        public boolean accept(Change it) {
            return it.getChangeTypeName().equals(changeTypeName);
        }
    });
    MutableSet<String> objectNames = objectTypeChanges.collect(new Function<Change, String>() {
        @Override
        public String valueOf(Change change) {
            return change.getObjectName();
        }
    }).collect(env.getPlatform().convertDbObjectName()).toSet();
    LookupIndex objectNameIndex = new LookupIndex(objectNames.toImmutable());
    return new ChecksumEntryInclusionPredicate(
            Lists.immutable.with(objectTypeIndex),
            Lists.immutable.with(objectNameIndex)
    );
}
 
示例4
private Predicate<? super ChecksumEntry> getPlatformInclusionPredicate(DbEnvironment env) {
    // 1) exclude those tables that are excluded by default from source code, e.g. explain tables or others that users configure
    ImmutableSet<Predicate<? super ChecksumEntry>> schemaObjectNamePredicates = env.getSchemas().collect(new Function<Schema, Predicate<? super ChecksumEntry>>() {
        @Override
        public Predicate<? super ChecksumEntry> valueOf(Schema schema) {
            return schema.getObjectExclusionPredicateBuilder().build(ChecksumEntry.TO_OBJECT_TYPE, ChecksumEntry.TO_NAME1);
        }
    });

    // 2) exclude the audit tables
    MutableMultimap<String, String> tablesToExclude = Multimaps.mutable.set.empty();

    tablesToExclude.putAll(ChangeType.TABLE_STR, Sets.immutable.with(
            env.getPlatform().convertDbObjectName().valueOf(getArtifactDeployerDao().getAuditContainerName()),
            env.getPlatform().convertDbObjectName().valueOf(dbChecksumManager.getChecksumContainerName()),
            env.getPlatform().convertDbObjectName().valueOf(getDeployExecutionDao().getExecutionContainerName()),
            env.getPlatform().convertDbObjectName().valueOf(getDeployExecutionDao().getExecutionAttributeContainerName())
    ));
    ObjectTypeAndNamePredicateBuilder auditTablePredicateBuilder = new ObjectTypeAndNamePredicateBuilder(tablesToExclude.toImmutable(), ObjectTypeAndNamePredicateBuilder.FilterType.EXCLUDE);
    Predicates<? super ChecksumEntry> auditTablePredicate = auditTablePredicateBuilder.build(ChecksumEntry.TO_OBJECT_TYPE, ChecksumEntry.TO_NAME1);

    return auditTablePredicate.and(schemaObjectNamePredicates);
}
 
示例5
private SortableDependencyGroup newChangeWithDependency(String schema, String changeTypeName, String objectName, String changeName, int orderWithinObject, ImmutableSet<CodeDependency> dependencies) {
    ChangeType changeType = mock(ChangeType.class);
    when(changeType.getName()).thenReturn(changeTypeName);
    when(changeType.isRerunnable()).thenReturn(true);

    SortableDependency sort = mock(SortableDependency.class);
    ObjectKey key = new ObjectKey(schema, objectName, changeType);
    when(sort.getChangeKey()).thenReturn(new ChangeKey(key, changeName));
    if (dependencies != null) {
        when(sort.getCodeDependencies()).thenReturn(dependencies);
    }
    when(sort.getOrderWithinObject()).thenReturn(orderWithinObject);

    // to print out a nice message for the mock; we do need the string variable on a separate line
    String keyString = key.toStringShort() + "-" + changeName;
    when(sort.toString()).thenReturn(keyString);

    SortableDependencyGroup depGroup = mock(SortableDependencyGroup.class);
    when(depGroup.getComponents()).thenReturn(Sets.immutable.<SortableDependency>with(sort));
    when(depGroup.toString()).thenReturn(keyString);
    return depGroup;
}
 
示例6
public void programmaticEnvCreation() {
    DbEnvironment dbEnv = new DbEnvironment();
    dbEnv.setSourceDirs(Lists.immutable.with(FileRetrievalMode.FILE_SYSTEM.resolveSingleFileObject("./src/test/resources/platforms/h2/step1")));
    dbEnv.setName("test");
    dbEnv.setPlatform(new H2DbPlatform());
    dbEnv.setSchemas(Sets.immutable.with(new Schema("SCHEMA1"), new Schema("SCHEMA2")));
    dbEnv.setDbServer("BLAH");

    dbEnv.setSchemaNameOverrides(Maps.immutable.of("SCHEMA1", "bogusSchema"));
    dbEnv.setNullToken("(null)");
    dbEnv.setDataDelimiter('^');

    DeployerAppContext context = Obevo.buildContext(dbEnv, new Credential("sa", ""));

    context.setupEnvInfra();
    context.cleanEnvironment();
    context.deploy();
}
 
示例7
private MainDeployerArgs getMainDeployerArgs() {
    MainDeployerArgs args = new MainDeployerArgs();

    if (this.tables != null || this.views != null) {
        MutableList<Predicate<? super ChangeKey>> predicates = Lists.mutable.empty();
        if (this.tables != null) {
            predicates.add(ChangeKeyPredicateBuilder.newBuilder()
                    .setChangeTypes(ChangeType.TABLE_STR, ChangeType.FOREIGN_KEY_STR, ChangeType.TRIGGER_INCREMENTAL_OLD_STR, ChangeType.STATICDATA_STR)
                    .setObjectNames(Sets.immutable.withAll(this.tables))
                    .build());
        }
        if (this.views != null) {
            predicates.add(ChangeKeyPredicateBuilder.newBuilder()
                    .setChangeTypes(ChangeType.VIEW_STR)
                    .setObjectNames(Sets.immutable.withAll(this.views))
                    .build());
        }

        args.setChangeInclusionPredicate(Predicates.or(predicates));
    }

    args.setAllChangesets(true);  // for unit tests, we always want all changes to deploy
    return args;
}
 
示例8
@Test
public void testPackageMetadataWithMetadataAndProperties() {
    PackageMetadataReader packageMetadataReader = new PackageMetadataReader(new TextMarkupDocumentReader(false));

    PackageMetadata packageMetadata = packageMetadataReader.getPackageMetadata("\n\n  \n  \n" +
            "//// METADATA k1=v1 k2=v2 toggle1 toggle2\n" +
            "sourceEncodings.UTF-8=a1,a2,a3\n" +
            "sourceEncodings.UTF-16=a4\n" +
            "otherProps=abc\n" +
            "\n");

    assertEquals(Maps.immutable.of("k1", "v1", "k2", "v2"), packageMetadata.getMetadataSection().getAttrs());
    assertEquals(Sets.immutable.of("toggle1", "toggle2"), packageMetadata.getMetadataSection().getToggles());

    assertEquals(Maps.mutable.of(
            "a1", "UTF-8",
            "a2", "UTF-8",
            "a3", "UTF-8",
            "a4", "UTF-16"
            )
            , packageMetadata.getFileToEncodingMap());
}
 
示例9
/**
 * The test data in this class is all written w/ case-sensitivy as the default.
 * If we pass caseInsensitive == true, then we enable that mode in the graph enricher and tweak the object names
 * a bit so that we can verify that the resolution works either way.
 */
private void testSchemaObjectDependencies(boolean caseInsensitive) {
    this.enricher = new GraphEnricherImpl(caseInsensitive ? String::toUpperCase : Functions.getStringPassThru()::valueOf);

    SortableDependencyGroup sch1Obj1 = newChange(schema1, type1, "obj1", Sets.immutable.with("obj3", schema2 + ".obj2"));
    SortableDependencyGroup sch1Obj2 = newChange(schema1, type2, "obj2", Sets.immutable.<String>with());
    // change the case of the object name to ensure others can still point to it
    SortableDependencyGroup sch1Obj3 = newChange(schema1, type1, caseInsensitive ? "obj3".toUpperCase() : "obj3", Sets.immutable.with("obj2"));
    // change the case of the dependency name to ensure that it can point to others
    SortableDependencyGroup sch2Obj1 = newChange(schema2, type1, "obj1", Sets.immutable.with(caseInsensitive ? "obj2".toUpperCase() : "obj2"));
    SortableDependencyGroup sch2Obj2 = newChange(schema2, type2, "obj2", Sets.immutable.with(schema1 + ".obj3"));

    Graph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with(
            sch1Obj1, sch1Obj2, sch1Obj3, sch2Obj1, sch2Obj2), false);

    validateChange(sortGraph, sch1Obj1, Sets.immutable.with(sch1Obj3, sch2Obj2), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sch1Obj2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sch1Obj3));
    validateChange(sortGraph, sch1Obj3, Sets.immutable.with(sch1Obj2), Sets.immutable.with(sch1Obj1, sch2Obj2));
    validateChange(sortGraph, sch2Obj1, Sets.immutable.with(sch2Obj2), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sch2Obj2, Sets.immutable.with(sch1Obj3), Sets.immutable.with(sch1Obj1, sch2Obj1));
}
 
示例10
@Test
public void test() {
    ChangeType changeType = mock(ChangeType.class);
    when(changeType.getName()).thenReturn("type");

    MongoDbPlatform platform = mock(MongoDbPlatform.class);
    when(platform.getChangeType(Mockito.anyString())).thenReturn(changeType);
    when(platform.convertDbObjectName()).thenReturn(StringFunctions.toUpperCase());

    Schema schema = new Schema("mydb");

    MongoDbEnvironment env = new MongoDbEnvironment();
    env.setPlatform(platform);
    env.setSchemas(Sets.immutable.of(schema));

    MongoDbDeployExecutionDao deployExecDao = new MongoDbDeployExecutionDao(mongoClient, env);

    DeployExecutionImpl exec = new DeployExecutionImpl("requester", "executor", schema.getName(), "1.0.0", new Timestamp(new Date().getTime()), false, false, "1.0.0", "reason", Sets.immutable.<DeployExecutionAttribute>empty());
    deployExecDao.persistNew(exec, new PhysicalSchema("mydb"));

    ImmutableCollection<DeployExecution> execs = deployExecDao.getDeployExecutions("mydb");
    assertEquals(1, execs.size());

    deployExecDao.update(execs.getFirst());
}
 
示例11
@Test
public void testGetActiveDeploymentsOnNormalCase() throws Exception {
    assertEquals(Lists.immutable.with(1L), rollbackDetector.getActiveDeployments(Sets.immutable.with(
            newExecution(1, "a")
    )).collect(new Function<DeployExecution, Long>() {
        @Override
        public Long valueOf(DeployExecution deployExecution1) {
            return deployExecution1.getId();
        }
    }));

    assertEquals(Lists.immutable.with(1L, 2L, 3L), rollbackDetector.getActiveDeployments(Sets.immutable.with(
            newExecution(1, "a")
            , newExecution(2, "b")
            , newExecution(3, "c")
    )).collect(new Function<DeployExecution, Long>() {
        @Override
        public Long valueOf(DeployExecution deployExecution) {
            return deployExecution.getId();
        }
    }));
}
 
示例12
@Test
public void testGetChangesCaseInsensitive() {
    this.enricher = new GraphEnricherImpl(String::toUpperCase);
    String schema1 = "schema1";
    String schema2 = "schema2";
    String type1 = "type1";

    SortableDependencyGroup sp1 = newChange(schema1, type1, "SP1", "n/a", 0, Sets.immutable.with("sp2"));
    SortableDependencyGroup sp2 = newChange(schema1, type1, "SP2", Sets.immutable.<String>with());
    SortableDependencyGroup sp3 = newChange(schema1, type1, "SP3", Sets.immutable.with("sp1", "sp2"));
    SortableDependencyGroup spA = newChange(schema1, type1, "SPA", Sets.immutable.with("sp3"));
    SortableDependencyGroup sp1Schema2 = newChange(schema2, type1, "sp1", "n/a", 0, Sets.immutable.with("sp2", schema1 + ".sp3"));
    SortableDependencyGroup sp2Schema2 = newChange(schema2, type1, "sP2", "n/a", 0, Sets.immutable.<String>with());

    Graph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with(
            sp1, sp2, sp3, spA, sp1Schema2, sp2Schema2), false);

    validateChange(sortGraph, sp1, Sets.immutable.with(sp2), Sets.immutable.with(sp3));
    validateChange(sortGraph, sp2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sp1, sp3));
    validateChange(sortGraph, sp3, Sets.immutable.with(sp1, sp2), Sets.immutable.with(spA, sp1Schema2));
    validateChange(sortGraph, spA, Sets.immutable.with(sp3), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sp1Schema2, Sets.immutable.with(sp2Schema2, sp3), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sp2Schema2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sp1Schema2));
}
 
示例13
@Test
public void testCycleValidationWithIncrementalChanges() {
    this.enricher = new GraphEnricherImpl(Functions.getStringPassThru()::valueOf);

    SortableDependencyGroup sch1Obj1C1 = newChange(schema1, type1, "obj1", "c1", 0, null);
    SortableDependencyGroup sch1Obj1C2 = newChangeWithDependency(schema1, type1, "obj1", "c2", 1, Sets.immutable.of(new CodeDependency("obj2", CodeDependencyType.DISCOVERED)));
    SortableDependencyGroup sch1Obj1C3 = newChange(schema1, type1, "obj1", "c3", 2, null);
    SortableDependencyGroup sch1Obj2C1 = newChange(schema1, type1, "obj2", "c1", 0, null);
    SortableDependencyGroup sch1Obj2C2 = newChange(schema1, type1, "obj2", "c2", 1, null);
    SortableDependencyGroup sch1Obj2C3 = newChange(schema1, type1, "obj2", "c3", 2, Sets.immutable.<String>with("obj1.c3"));
    SortableDependencyGroup sch1Obj3 = newChange(schema1, type1, "obj3", Sets.immutable.with("obj1"));

    try {
        enricher.createDependencyGraph(Lists.mutable.with(
                sch1Obj1C1, sch1Obj1C2, sch1Obj1C3, sch1Obj2C1, sch1Obj2C2, sch1Obj2C3, sch1Obj3), false);
        fail("Expecting an exception here due to a cycle exception, but a cycle exception was not found");
    } catch (IllegalArgumentException exc) {
        exc.printStackTrace();
        assertThat(exc.getMessage(), containsString("Found cycles"));
        // verify that we print a legible error message for discovered dependencies
        assertThat(exc.getMessage(), containsString("[obj1.c2] == depends on ==> [obj2]   (DISCOVERED dependency)"));
    }
}
 
示例14
@Test
public void testQuotedSplitWithEqualSign() {
    String input = "attr=1234 attr2=\"56=78\" mytog1";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should have failed here");
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), containsString("Cannot mark = multiple times"));
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);

        assertEquals(Maps.mutable.of("attr", "1234", "attr2", "56=78"), results.getOne());
        assertEquals(Sets.mutable.of("mytog1"), results.getTwo());
    }
}
 
示例15
@Test
public void testQuotedSplitWithEqualSignAndSpace() {
    String input = "attr=1234 attr2=\"56 = 78\" mytog1";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should have failed here");
        } catch (ArrayIndexOutOfBoundsException e) {
            assertThat(e.getMessage(), notNullValue());
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);

        assertEquals(Maps.mutable.of("attr", "1234", "attr2", "56 = 78"), results.getOne());
        assertEquals(Sets.mutable.of("mytog1"), results.getTwo());
    }
}
 
示例16
@Test
public void testWordEndingInEqualSignWillFailInLegacy() {
    String input = "   attr= abc";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should have failed here");
        } catch (ArrayIndexOutOfBoundsException expected) {
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);

        assertEquals(Maps.mutable.of("attr", ""), results.getOne());
        assertEquals(Sets.mutable.of("abc"), results.getTwo());
    }
}
 
示例17
/**
 * The pass. Thread safe
 *
 * @param color the type of pass
 */
private void pass(Stone color) {
    synchronized (this) {
        // Forbid passing if the current move is before the move when try play state began
        if (isInTryPlayState() && history.getMoveNumber() < getTryPlayStateBeginMoveNumber()) {
            return;
        }

        // Forbid successive two passing
        if (history.getLastMove() == null && !Objects.equals(history.getLastMoveColor(), Stone.EMPTY)) {
            return;
        }

        // If pass move happens in history middle, auto swith to try play mode
        if (Lizzie.optionSetting.isAutoEnterTryPlayingMode() && !isInTryPlayState() && getHistory().getHead().getNext() != null) {
            enterTryPlayState();
        }

        Stone[] stones = history.getStones().clone();
        Zobrist zobrist = history.getZobrist();
        int moveNumber = history.getMoveNumber() + 1;
        int[] moveNumberList = history.getMoveNumberList().clone();

        // build the new game state
        BoardData newState = new BoardData(stones, null, color, !history.isBlacksTurn(), zobrist, moveNumber, moveNumberList, Sets.mutable.empty(), history.getData().getBlackPrisonersCount(), history.getData().getWhitePrisonersCount());

        // update history with pass
        if (history.getHead().getNext() != null) {
            history.getHead().disconnectNextNode();
            observerCollection.mainStreamCut(history.getHead(), history.getHead());
        }
        BoardHistoryNode oldHead = history.getHead();
        history.add(newState);
        BoardHistoryNode newHead = history.getHead();
        observerCollection.mainStreamAppended(newHead, oldHead);
        observerCollection.headMoved(oldHead, newHead);
    }
}
 
示例18
/**
 * Get all the pets who's owner's last name is "Smith"
 * Extra credit: try getting the list of people and then the list of pets from the people list.
 */
@Test
public void getAllPetsOfSmiths()
{
    PetList smithPets = null;

    Verify.assertSetsEqual(Sets.mutable.with("Dolly", "Spike", "Tabby", "Spot"),
            smithPets.asEcList().collect(TO_PET_NAME, Sets.mutable.empty()));
}
 
示例19
@Test
public void testPackageMetadataWithMetadata() {
    PackageMetadataReader packageMetadataReader = new PackageMetadataReader(new TextMarkupDocumentReader(false));

    PackageMetadata packageMetadata = packageMetadataReader.getPackageMetadata("\n\n  \n  \n" +
            "//// METADATA k1=v1 k2=v2 toggle1 toggle2\n" +
            "\n");

    assertEquals(Maps.immutable.of("k1", "v1", "k2", "v2"), packageMetadata.getMetadataSection().getAttrs());
    assertEquals(Sets.immutable.of("toggle1", "toggle2"), packageMetadata.getMetadataSection().getToggles());

    assertEquals(Maps.immutable.<String, String>empty(), packageMetadata.getFileToEncodingMap());
}
 
示例20
@Test
public void testCycleDetection() {
    SortableDependency sp1 = newVertex("sp1");
    SortableDependency sp2 = newVertex("sp2");
    SortableDependency sp3 = newVertex("sp3");
    SortableDependency sp4 = newVertex("sp4");
    SortableDependency sp5 = newVertex("sp5");
    SortableDependency sp6 = newVertex("sp6");
    SortableDependency sp7 = newVertex("sp7");
    SortableDependency sp8 = newVertex("sp8");

    Graph<SortableDependency, DefaultEdge> graph = new DefaultDirectedGraph<SortableDependency, DefaultEdge>(DefaultEdge.class);
    for (SortableDependency vertex : shuffledList(sp1, sp2, sp3, sp4, sp5, sp6, sp7, sp8)) {
        graph.addVertex(vertex);
    }

    graph.addEdge(sp2, sp1);
    graph.addEdge(sp5, sp4);
    graph.addEdge(sp1, sp5);
    graph.addEdge(sp3, sp5);
    graph.addEdge(sp4, sp5);
    graph.addEdge(sp6, sp5);
    graph.addEdge(sp7, sp6);
    graph.addEdge(sp8, sp7);
    graph.addEdge(sp6, sp8);

    try {
        sorter.sortChanges(graph);
        fail("Expecting exception here: " + GraphCycleException.class);
    } catch (GraphCycleException e) {
        verifyCycleExists(e, Sets.immutable.with("sp4", "sp5"));
        verifyCycleExists(e, Sets.immutable.with("sp6", "sp7", "sp8"));
        Verify.assertSize(2, e.getCycleComponents());
    }
}
 
示例21
private void testMe(String prefix, String suffix, String compareFile) {
    String schema1 = "schema1";
    String schema2 = "schema2";
    String schema2Changed = "schema2Changed";

    // Setup the db config w/ env _d1
    DbEnvironment env = mock(DbEnvironment.class);
    when(env.getDbSchemaPrefix()).thenReturn("");
    when(env.getDbSchemaSuffix()).thenReturn("_d1");
    when(env.getPhysicalSchemaPrefixInternal(schema1)).thenReturn(schema1);
    when(env.getPhysicalSchemaPrefixInternal(schema2)).thenReturn(schema2Changed);
    when(env.getTokens()).thenReturn(Maps.immutable.with("Param", "is this"));
    when(env.getTokenPrefix()).thenReturn(prefix);
    when(env.getTokenSuffix()).thenReturn(suffix);
    when(env.getSchemas()).thenReturn(Sets.immutable.<Schema>empty());

    // now setup the files
    String filePath = "deploy/PrepareDbChangeForDbTest/TableA.1.ddl";
    File sourcePath = new File("./src/test/resources");

    String content = FileUtilsCobra.readFileToString(new File(sourcePath, filePath));

    PrepareDbChangeForDb processor = new PrepareDbChangeForDb();

    // execute the output
    String output = processor.prepare(content, null, env);

    // verify the result
    File expectedOutputFile = new File(compareFile);
    String expectedContent = FileUtilsCobra.readFileToString(expectedOutputFile);
    assertEquals(expectedContent, output);
}
 
示例22
@Test
public void testComboInSinglePredicate() {
    Predicate<ChangeKey> comboPredicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("sc%1~%~objA,mytableC~%");
    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjCChng1),
            allChanges.select(comboPredicate).toSet());
}
 
示例23
@Test
public void testSlashWithQuoteNoEscaping() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            " 123  attr=\"abc\\\"d ef\"  \\  456=789"
    );

    if (legacyMode) {
        assertEquals(Maps.mutable.of("attr", "\"abc\\\"d", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\", "ef\""), results.getTwo());
    } else {
        assertEquals(Maps.mutable.of("attr", "abc\"d ef", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\"), results.getTwo());
    }
}
 
示例24
@Test
public void ref() throws JsonProcessingException {
    Assert.assertEquals(
            "[\"a\",\"b\",\"c\"]",
            mapperWithModule().writeValueAsString(Sets.immutable.of("a", "b", "c"))
    );
}
 
示例25
private void validateEnv2(MongoDbEnvironment env2) {
    assertThat(env2.getHost(), equalTo("localhost"));
    assertThat(env2.getPort(), equalTo(10001));
    assertThat(env2.getSchemaNames(), equalTo(Sets.immutable.of("MYSCHEMA")));
    assertThat(env2.getPhysicalSchema("MYSCHEMA").getPhysicalName(), equalTo("MYSCHEMA_TEST2"));
    assertThat(env2.getTokens(), equalTo(Maps.immutable.of("key", "val")));
}
 
示例26
@Test
public void test() {
    ChangeType changeType = mock(ChangeType.class);
    when(changeType.getName()).thenReturn("type");

    MongoDbPlatform platform = mock(MongoDbPlatform.class);
    when(platform.getChangeType(Mockito.anyString())).thenReturn(changeType);
    when(platform.convertDbObjectName()).thenReturn(s -> s);

    MongoDbEnvironment env = mock(MongoDbEnvironment.class);
    env = new MongoDbEnvironment();
    Schema schema = new Schema("mydb");
    env.setSchemas(Sets.immutable.of(schema));
    env.setPlatform(platform);

    MongoDbDeployExecutionDao deployExecutionDao = new MongoDbDeployExecutionDao(mongoClient, env);

    // test initial persistence
    deployExecutionDao.persistNew(new DeployExecutionImpl("requester", "executor", schema.getName(), "1.0.0", new Timestamp(new Date().getTime()), false, false, "1.0.0", "reason", Sets.immutable.empty()), env.getPhysicalSchema(schema));
    // do a second deployment to verify incrementing logic
    DeployExecutionImpl exec2 = new DeployExecutionImpl("requester", "executor", schema.getName(), "1.0.0", new Timestamp(new Date().getTime()), false, false, "2.0.0", "reason", Sets.immutable.empty());
    deployExecutionDao.persistNew(exec2, env.getPhysicalSchema(schema));

    MongoDbChangeAuditDao changeAuditDao = new MongoDbChangeAuditDao(mongoClient, env, platform, "test", deployExecutionDao);


    Change change = new ChangeIncremental(changeType, "mydb", "obj1", "c1", 0, "hash", "content");

    changeAuditDao.insertNewChange(change, exec2);
    ImmutableList<Change> deployedChanges = changeAuditDao.getDeployedChanges();
    assertEquals(1, deployedChanges.size());
    assertEquals(2, deployedChanges.get(0).getDeployExecution().getId());
    assertEquals("2.0.0", deployedChanges.get(0).getDeployExecution().getProductVersion());

}
 
示例27
@Override
public ImmutableSet<String> getDisabledChangeTypeNames() {
    return Sets.immutable.with(
            ChangeType.DEFAULT_STR,
            ChangeType.FUNCTION_STR,
            ChangeType.RULE_STR,
            ChangeType.SP_STR,
            ChangeType.TRIGGER_STR,
            ChangeType.TRIGGER_INCREMENTAL_OLD_STR
    );
}
 
示例28
@Override
public ImmutableSet<String> getDisabledChangeTypeNames() {
    return Sets.immutable.with(
            ChangeType.DEFAULT_STR,
            ChangeType.FUNCTION_STR,
            ChangeType.RULE_STR,
            ChangeType.SP_STR,
            ChangeType.TRIGGER_STR,
            ChangeType.TRIGGER_INCREMENTAL_OLD_STR
    );
}
 
示例29
@Override
public List<Stage.ConfigIssue> validateConfigs(Stage.Context context, List<Stage.ConfigIssue> issues) {
  issues = superValidateConfigs(context, issues);

  try {
    if (isEncryptedConnection) {
      encryptionProperties = new Properties();
      KeyStoreBuilder builder = new KeyStoreBuilder().addCertificatePem(serverCertificatePem);
      KeyStoreIO.KeyStoreFile jks = KeyStoreIO.save(builder.build());
      encryptionProperties.setProperty(TRUSTSTORE_TYPE, "JKS");
      encryptionProperties.setProperty(TRUSTSTORE, jks.getPath());
      encryptionProperties.setProperty(TRUSTSTORE_PASSWORD, jks.getPassword());
      encryptionProperties.setProperty(SSL_CLIENT_AUTHENTICATION, "false");

      encryptionProperties.setProperty(SSL_CIPHER_SUITES, cipherSuites.trim());
      encryptionProperties.setProperty(SSL_SERVER_DN_MATCH, String.valueOf(verifyHostname));
    }

    constructConnectionString();

  } catch (StageException e) {
    issues.add(context.createConfigIssue("ENCRYPTION",
        "hikariConfigBean.serverCertificatePem",
        Errors.ORACLE_01,
        e.getMessage()
    ));
  }
  Set<String> blacklistedInUse = Sets.intersect(BLACKLISTED_PROPS, super.getDriverProperties().stringPropertyNames());
  if (!blacklistedInUse.isEmpty()) {
    issues.add(context.createConfigIssue("JDBC", "driverProperties", Errors.ORACLE_00, blacklistedInUse));
  }
  return issues;
}
 
示例30
@Test
public void objectSet() throws IOException {
    testCollection(Sets.mutable.of("a", Collections.emptyMap(), 1), "[\"a\", {}, 1]",
            new TypeReference<MutableSet>() {},
            new TypeReference<ImmutableSet>() {});
    testCollection(Sets.mutable.of("a", Collections.emptyMap(), 1), "[\"a\", {}, 1]",
            MutableSet.class,
            ImmutableSet.class);
}