org.eclipse.collections.api.set.ImmutableSet Java Examples

The following examples show how to use org.eclipse.collections.api.set.ImmutableSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #2
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #3
Source File: GraphEnricherImplTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #5
Source File: BaselineValidatorMainTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaselineMismatchScenario() {
    DbDeployerAppContext appContext = DbEnvironmentFactory.getInstance().readOneFromSourcePath("baselineutil/BaselineValidatorMain/uc1", "test")
            .buildAppContext();

    BaselineValidatorMain main = new BaselineValidatorMain();
    ImmutableSet<CompareBreak> compareBreaks = main.calculateBaselineBreaks(appContext);

    System.out.println("BREAKS\n" + compareBreaks.makeString("\n"));

    assertEquals(2, compareBreaks.size());
    ObjectCompareBreak objectBreak = (ObjectCompareBreak) compareBreaks.detect(Predicates
            .instanceOf(ObjectCompareBreak.class));

    FieldCompareBreak dataTypeBreak = (FieldCompareBreak) compareBreaks.select(
            Predicates.instanceOf(FieldCompareBreak.class)).detect(new Predicate<CompareBreak>() {
        @Override
        public boolean accept(CompareBreak each) {
            return ((FieldCompareBreak) each).getFieldName().equalsIgnoreCase("columnDataType");
        }
    });

    assertNotNull(objectBreak);
    assertNotNull(dataTypeBreak);
}
 
Example #6
Source File: DbDeployer.java    From obevo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: Db2SqlExecutor.java    From obevo with Apache License 2.0 5 votes vote down vote up
/**
 * Package-private for unit testing only.
 */
static String getCurrentPathSql(Connection conn, JdbcHelper jdbc, ImmutableSet<PhysicalSchema> physicalSchemas) {
    String path = jdbc.query(conn, "select current path from sysibm.sysdummy1", new ScalarHandler<String>());

    MutableList<String> currentSchemaPathList = Lists.mutable.of(path.split(",")).collect(new Function<String, String>() {
        @Override
        public String valueOf(String object) {
            if (object.startsWith("\"") && object.endsWith("\"")) {
                return object.substring(1, object.length() - 1);
            } else {
                return object;
            }
        }
    });

    // Rules on constructing this "set path" command:
    // 1) The existing default path must come first (respecting the existing connection), followed by the
    // schemas in our environment. The default path must take precedence.
    // 2) We cannot have duplicate schemas listed in the "set path" call; i.e. in case the schemas in our
    // environment config are already in the default schema.
    //
    // Given these two requirements, we use a LinkedHashSet
    LinkedHashSet<String> currentSchemaPaths = new LinkedHashSet(currentSchemaPathList);
    currentSchemaPaths.addAll(physicalSchemas.collect(new Function<PhysicalSchema, String>() {
        @Override
        public String valueOf(PhysicalSchema physicalSchema) {
            return physicalSchema.getPhysicalName();
        }
    }).castToSet());

    // This is needed to work w/ stored procedures
    // Ideally, we'd use "set current path current path, " + physicalSchemaList
    // However, we can't set this multiple times in a connection, as we can't have dupes in "current path"
    // Ideally, we could use BasicDataSource.initConnectionSqls, but this does not interoperate w/ the LDAP
    // datasource for JNDI-JDBC
    return "set path " + CollectionAdapter.adapt(currentSchemaPaths).makeString(",");
}
 
Example #8
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualSignInQuoteValueWillFailInLegacy() {
    String input = "   attr=\"abc=123\" ";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should throw exception here");
        } catch (IllegalArgumentException expected) {
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);
        assertEquals(Maps.mutable.of("attr", "abc=123"), results.getOne());
        assertEquals(Sets.mutable.empty(), results.getTwo());
    }
}
 
Example #9
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #10
Source File: DbDeployer.java    From obevo with Apache License 2.0 5 votes vote down vote up
private Predicate<? super ChecksumEntry> getSourceChangesInclusionPredicate(final DbEnvironment env, final ImmutableList<Change> sourceChanges) {
    // 3) only include the predicate types that we care about
    ImmutableSet<String> requiredValidationObjectTypes = env.getPlatform().getRequiredValidationObjectTypes();
    ImmutableSet<ChecksumEntryInclusionPredicate> checksumEntryPredicates = requiredValidationObjectTypes.collect(new Function<String, ChecksumEntryInclusionPredicate>() {
        @Override
        public ChecksumEntryInclusionPredicate valueOf(String changeType) {
            return createLookupIndexForObjectType(env, sourceChanges, changeType);
        }
    });

    return Predicates.or(checksumEntryPredicates);
}
 
Example #11
Source File: DbMetadataManagerImpl.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableSet<DaDirectory> getDirectoriesOptional() {
    try (Connection conn = ds.getConnection()) {
        return this.dbMetadataDialect.getDirectoriesOptional(conn);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
Example #12
Source File: DbMetadataManagerImpl.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableSet<DaExtension> getExtensionsOptional() {
    try (Connection conn = ds.getConnection()) {
        return this.dbMetadataDialect.getExtensionsOptional(conn);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
Example #13
Source File: Db2MetadataDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableSet<String> getGroupNamesOptional(Connection conn, PhysicalSchema physicalSchema) throws SQLException {
    return Sets.immutable
            .withAll(jdbc.query(conn, "select ROLENAME from sysibm.SYSROLES", new ColumnListHandler<String>()))
            .newWithAll(jdbc.query(conn, "select GRANTEE from sysibm.SYSDBAUTH", new ColumnListHandler<String>()))
            .collect(StringFunctions.trim());  // db2 sometimes has whitespace in its return results that needs trimming
}
 
Example #14
Source File: MsSqlToHsqlTranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@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
    );
}
 
Example #15
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSlashWithQuoteNoEscaping2() {
    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());
    }
}
 
Example #16
Source File: Db2ToHsqlTranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableSet<String> getDisabledChangeTypeNames() {
    return Sets.immutable.with(
            ChangeType.DEFAULT_STR,
            ChangeType.FUNCTION_STR,
            ChangeType.RULE_STR,
            ChangeType.SEQUENCE_STR,
            ChangeType.SP_STR,
            ChangeType.TRIGGER_STR,
            ChangeType.TRIGGER_INCREMENTAL_OLD_STR
    );
}
 
Example #17
Source File: FileSourceParams.java    From obevo with Apache License 2.0 5 votes vote down vote up
private FileSourceParams(RichIterable<FileObject> files, ImmutableSet<String> schemaNames, boolean baseline, ImmutableList<ChangeType> changeTypes, ImmutableSet<String> acceptedExtensions, String defaultSourceEncoding, boolean legacyDirectoryStructureEnabled) {
    this.files = files;
    this.schemaNames = schemaNames;
    this.baseline = baseline;
    this.changeTypes = changeTypes;
    this.acceptedExtensions = acceptedExtensions;
    this.defaultSourceEncoding = defaultSourceEncoding;
    this.legacyDirectoryStructureEnabled = legacyDirectoryStructureEnabled;
}
 
Example #18
Source File: AseToHsqlTranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@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
    );
}
 
Example #19
Source File: AseToH2TranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@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
    );
}
 
Example #20
Source File: IqToHsqlTranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableSet<String> getDisabledChangeTypeNames() {
    return Sets.immutable.with(
            ChangeType.DEFAULT_STR,
            ChangeType.FUNCTION_STR,
            ChangeType.RULE_STR,
            ChangeType.SEQUENCE_STR,
            ChangeType.SP_STR,
            ChangeType.TRIGGER_STR,
            ChangeType.TRIGGER_INCREMENTAL_OLD_STR
    );
}
 
Example #21
Source File: IqToH2TranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@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
    );
}
 
Example #22
Source File: DeployExecutionImpl.java    From obevo with Apache License 2.0 5 votes vote down vote up
public DeployExecutionImpl(String requesterId, String deployExecutorId, String schema, String toolVersion, Timestamp deployTime, boolean init, boolean rollback, String productVersion, String reason, ImmutableSet<? extends DeployExecutionAttribute> attributes) {
    this.requesterId = requesterId;
    this.executorId = deployExecutorId;
    this.schema = schema;
    this.toolVersion = toolVersion;
    this.deployTime = deployTime;
    this.init = init;
    this.rollback = rollback;
    this.productVersion = productVersion;
    this.reason = reason;
    this.attributes = attributes != null ? attributes : Sets.immutable.<DeployExecutionAttribute>empty();
}
 
Example #23
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualSignAloneWillFailInLegacy() {
    String input = " a = b ";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should throw exception here");
        } catch (ArrayIndexOutOfBoundsException expected) {
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);
        assertEquals(Maps.mutable.empty(), results.getOne());
        assertEquals(Sets.mutable.of("a", "b", "="), results.getTwo());
    }
}
 
Example #24
Source File: Environment.java    From obevo with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the schemas to be deployed to by the application. We do not include readOnly schemas for compatibility
 * with the rest of the code.
 */
public ImmutableSet<Schema> getSchemas() {
    return this.allSchemas.reject(new Predicate<Schema>() {
        @Override
        public boolean accept(Schema schema) {
            return schema.isReadOnly();
        }
    });
}
 
Example #25
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuoteWithinQuotedStringIsPreservedIfNoSpace() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            "   abc=attr  1234 attr2=\"56\"78\" mytog1  "
    );

    assertEquals(Maps.mutable.of("abc", "attr", "attr2", "56\"78"), results.getOne());
    assertEquals(Sets.mutable.of("1234", "mytog1"), results.getTwo());
}
 
Example #26
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleLineParsing() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            "attr=1234 attr2=\"5678\" mytog1"
    );

    assertEquals(Maps.mutable.of("attr", "1234", "attr2", "5678"), results.getOne());
    assertEquals(Sets.mutable.of("mytog1"), results.getTwo());
}
 
Example #27
Source File: Change.java    From obevo with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableSet<SortableDependency> getComponents() {
    return Sets.immutable.<SortableDependency>with(this);
}
 
Example #28
Source File: Change.java    From obevo with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableSet<CodeDependency> getCodeDependencies() {
    return dependencies;
}
 
Example #29
Source File: LookupIndex.java    From obevo with Apache License 2.0 4 votes vote down vote up
public LookupIndex(ImmutableSet<String> values) {
    this.values = values;
}
 
Example #30
Source File: GraphEnricherImplTest.java    From obevo with Apache License 2.0 4 votes vote down vote up
private SortableDependencyGroup newChange(String schema, String changeTypeName, String objectName, String changeName, int orderWithinObject, ImmutableSet<String> dependencies) {
    ImmutableSet<CodeDependency> codeDependencies = dependencies == null ? null : dependencies.collectWith(CodeDependency::new, CodeDependencyType.EXPLICIT);
    return newChangeWithDependency(schema, changeTypeName, objectName, changeName, orderWithinObject, codeDependencies);
}