@Test public void testWrap_StringChar() { assertNull(StringUtils.wrap(null, CharUtils.NUL)); assertNull(StringUtils.wrap(null, '1')); assertEquals("", StringUtils.wrap("", CharUtils.NUL)); assertEquals("xabx", StringUtils.wrap("ab", 'x')); assertEquals("\"ab\"", StringUtils.wrap("ab", '\"')); assertEquals("\"\"ab\"\"", StringUtils.wrap("\"ab\"", '\"')); assertEquals("'ab'", StringUtils.wrap("ab", '\'')); assertEquals("''abcd''", StringUtils.wrap("'abcd'", '\'')); assertEquals("'\"abcd\"'", StringUtils.wrap("\"abcd\"", '\'')); assertEquals("\"'abcd'\"", StringUtils.wrap("'abcd'", '\"')); }
@Test public void testWrap_StringString() { assertNull(StringUtils.wrap(null, null)); assertNull(StringUtils.wrap(null, "")); assertNull(StringUtils.wrap(null, "1")); assertNull(StringUtils.wrap(null, null)); assertEquals("", StringUtils.wrap("", "")); assertEquals("ab", StringUtils.wrap("ab", null)); assertEquals("xabx", StringUtils.wrap("ab", "x")); assertEquals("\"ab\"", StringUtils.wrap("ab", "\"")); assertEquals("\"\"ab\"\"", StringUtils.wrap("\"ab\"", "\"")); assertEquals("'ab'", StringUtils.wrap("ab", "'")); assertEquals("''abcd''", StringUtils.wrap("'abcd'", "'")); assertEquals("'\"abcd\"'", StringUtils.wrap("\"abcd\"", "'")); assertEquals("\"'abcd'\"", StringUtils.wrap("'abcd'", "\"")); }
private static String getTableName(String dbName, Class<?> cls) { String tableName = StringUtils.wrap(getEntitySimpleName(cls), '`'); if (dbName != null) { return new StringBuilder().append('`').append(dbName).append("`.").append(tableName).toString(); } else { return tableName; } }
private String[] toStringArray(List<Object> columnValues) { String[] result = new String[columnValues.size()]; for (int i = 0; i < columnValues.size(); i++) { if (columnValues.get(i) instanceof String) { result[i] = wrap((String) columnValues.get(i), '\''); } else { result[i] = columnValues.get(i).toString(); } } return result; }
protected String getQueryString() throws IOException { String condition = null; if (properties.manualQuery.getValue()) { return properties.getQuery(); } else { condition = properties.condition.getStringValue(); } StringBuilder sb = new StringBuilder(); boolean isUpperCase = properties.convertColumnsAndTableToUppercase.getValue(); sb.append("select "); //$NON-NLS-1$ int count = 0; for (Schema.Field se : getSchema().getFields()) { if (count++ > 0) { sb.append(", "); //$NON-NLS-1$ } String columnName = se.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME); sb.append(isUpperCase ? columnName : StringUtils.wrap(columnName, '"')); } sb.append(" from "); //$NON-NLS-1$ String tableName = isUpperCase ? properties.getTableName() : StringUtils.wrap(properties.getTableName(), '"'); sb.append(tableName); if (condition != null && condition.trim().length() > 0) { sb.append(" where "); sb.append(condition); } return sb.toString(); }
protected String getQueryString() throws IOException { String condition = null; if (properties.manualQuery.getValue()) { return properties.getQuery(); } else { condition = properties.condition.getStringValue(); } StringBuilder sb = new StringBuilder(); boolean isUpperCase = properties.convertColumnsAndTableToUppercase.getValue(); sb.append("select "); //$NON-NLS-1$ int count = 0; for (Schema.Field se : getSchema().getFields()) { if (count++ > 0) { sb.append(", "); //$NON-NLS-1$ } String columnName = se.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME); sb.append(isUpperCase ? columnName : StringUtils.wrap(columnName, '"')); } sb.append(" from "); //$NON-NLS-1$ String tableName = isUpperCase ? properties.getTableName() : StringUtils.wrap(properties.getTableName(), '"'); sb.append(tableName); if (condition != null && condition.trim().length() > 0) { sb.append(" where "); sb.append(condition); } return sb.toString(); }
protected String getQueryString() throws IOException { String condition = null; if (properties.manualQuery.getValue()) { return properties.query.getStringValue(); } else { condition = properties.condition.getStringValue(); } StringBuilder sb = new StringBuilder(); boolean isUpperCase = properties.convertColumnsAndTableToUppercase.getValue(); sb.append("select "); //$NON-NLS-1$ int count = 0; for (Schema.Field se : getSchema().getFields()) { if (count++ > 0) { sb.append(", "); //$NON-NLS-1$ } String columnName = se.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME); sb.append(isUpperCase ? columnName : StringUtils.wrap(columnName, '"')); } sb.append(" from "); //$NON-NLS-1$ String tableName = isUpperCase ? properties.getTableName() : StringUtils.wrap(properties.getTableName(), '"'); sb.append(tableName); if (condition != null && condition.trim().length() > 0) { sb.append(" where "); sb.append(condition); } return sb.toString(); }
@Test public void testGetJobsAssertJobNameTrimmed() throws Exception { String namespace = "namespace"; String jobName = StringUtils.wrap("jobName", BLANK_TEXT); JobStatusEnum jobStatus = JobStatusEnum.COMPLETED; Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList("namespace")); when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces); NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(namespace); when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity); jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME); verify(jobDefinitionDao).getJobDefinitionsByFilter(eq(authorizedNamespaces), eq(jobName.trim())); }
@Test public void checkPermissionsAssertRoleNameIsTrimmed() { NamespaceEntity expectedNamespaceEntity = new NamespaceEntity(); String iamRoleName1 = "iamRoleName1"; String iamRoleName2 = "iamRoleName2"; Collection<String> requestedIamRoleNames = Arrays.asList(StringUtils.wrap(iamRoleName1, BLANK_TEXT), StringUtils.wrap(iamRoleName2, BLANK_TEXT)); List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>(); NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity(); namespaceIamRoleAuthorizationEntity1.setIamRoleName(iamRoleName1); namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1); NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity(); namespaceIamRoleAuthorizationEntity2.setIamRoleName(iamRoleName2); namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2); when(configurationHelper.getBooleanProperty(any())).thenReturn(true); when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities); namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames); verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED); verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity); verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao); }
@Test public void testGetActiveEmrClusterIdAssertParametersTrimmed() { EmrDao originalEmrDao = emrHelper.getEmrDao(); EmrDao mockEmrDao = mock(EmrDao.class); emrHelper.setEmrDao(mockEmrDao); try { String emrClusterId = "emrClusterId"; String emrClusterName = "emrClusterName"; String expectedEmrClusterId = "expectedEmrClusterId"; when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn( new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING))); assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(StringUtils.wrap(emrClusterId, BLANK_TEXT), StringUtils.wrap(emrClusterName, BLANK_TEXT), null)); verify(mockEmrDao).getEmrClusterById(eq(emrClusterId.trim()), any()); verifyNoMoreInteractions(mockEmrDao); } finally { emrHelper.setEmrDao(originalEmrDao); } }
customLookupField.setValue(value != null ? StringUtils.wrap(value, '"') : ""); LOG.warn("[postDeserialize] Fixing Custom lookupField with {}", customLookupField.getValue());
customLookupField.setValue(value != null ? StringUtils.wrap(value, '"') : ""); LOG.warn("[postDeserialize] Fixing Custom lookupField with {}", customLookupField.getValue());
customLeadKeyType.setValue(value != null ? StringUtils.wrap(value, '"') : ""); LOG.warn("[postDeserialize] Fixing Custom leadKeyType with {}", customLeadKeyType.getValue());
customLeadKeyType.setValue(value != null ? StringUtils.wrap(value, '"') : ""); LOG.warn("[postDeserialize] Fixing Custom leadKeyType with {}", customLeadKeyType.getValue());