src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
StringUtils { public static String newStringUtf16(final byte[] bytes) { return new String(bytes, Charsets.UTF_16); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName...
@Test public void testNewStringUtf16() throws UnsupportedEncodingException { final String charsetName = "UTF-16"; testNewString(charsetName); final String expected = new String(BYTES_FIXTURE, charsetName); final String actual = StringUtils.newStringUtf16(BYTES_FIXTURE); Assert.assertEquals(expected, actual); }
LessThanOp extends Param1Op { @Override public String keyword() { return "LessThan"; } @Override String keyword(); @Override String operator(); }
@Test public void test() throws Exception { Op op = new LessThanOp(); assertThat(op.keyword(), equalTo("LessThan")); assertThat(op.paramCount(), equalTo(1)); assertThat(op.render("id", new String[] {":1"}), equalTo("id < :1")); }
StringUtils { public static String newStringUtf16Be(final byte[] bytes) { return new String(bytes, Charsets.UTF_16BE); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charset...
@Test public void testNewStringUtf16Be() throws UnsupportedEncodingException { final String charsetName = "UTF-16BE"; testNewString(charsetName); final String expected = new String(BYTES_FIXTURE_16BE, charsetName); final String actual = StringUtils.newStringUtf16Be(BYTES_FIXTURE_16BE); Assert.assertEquals(expected, act...
StringUtils { public static String newStringUtf16Le(final byte[] bytes) { return new String(bytes, Charsets.UTF_16LE); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charset...
@Test public void testNewStringUtf16Le() throws UnsupportedEncodingException { final String charsetName = "UTF-16LE"; testNewString(charsetName); final String expected = new String(BYTES_FIXTURE_16LE, charsetName); final String actual = StringUtils.newStringUtf16Le(BYTES_FIXTURE_16LE); Assert.assertEquals(expected, act...
StringUtils { public static String newStringUtf8(final byte[] bytes) { return newString(bytes, Charsets.UTF_8); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); ...
@Test public void testNewStringUtf8() throws UnsupportedEncodingException { final String charsetName = "UTF-8"; testNewString(charsetName); final String expected = new String(BYTES_FIXTURE, charsetName); final String actual = StringUtils.newStringUtf8(BYTES_FIXTURE); Assert.assertEquals(expected, actual); }
BaseNCodec implements BinaryEncoder, BinaryDecoder { protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, final int chunkSeparatorLength) { this(unencodedBlockSize, encodedBlockSize, lineLength, chunkSeparatorLength, PAD_DEFAULT); } protected BaseNCodec(final int unencod...
@Test public void testBaseNCodec() { assertNotNull(codec); }
BaseNCodec implements BinaryEncoder, BinaryDecoder { protected static boolean isWhiteSpace(final byte byteToCheck) { switch (byteToCheck) { case ' ' : case '\n' : case '\r' : case '\t' : return true; default : return false; } } protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, ...
@Test public void testIsWhiteSpace() { assertTrue(BaseNCodec.isWhiteSpace((byte) ' ')); assertTrue(BaseNCodec.isWhiteSpace((byte) '\n')); assertTrue(BaseNCodec.isWhiteSpace((byte) '\r')); assertTrue(BaseNCodec.isWhiteSpace((byte) '\t')); }
BaseNCodec implements BinaryEncoder, BinaryDecoder { protected abstract boolean isInAlphabet(byte value); protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, final int chunkSeparatorLength); protected BaseNCodec(final int unencodedBlockSize, fi...
@Test public void testIsInAlphabetByte() { assertFalse(codec.isInAlphabet((byte) 0)); assertFalse(codec.isInAlphabet((byte) 'a')); assertTrue(codec.isInAlphabet((byte) 'O')); assertTrue(codec.isInAlphabet((byte) 'K')); } @Test public void testIsInAlphabetByteArrayBoolean() { assertTrue(codec.isInAlphabet(new byte[]{}, ...
BaseNCodec implements BinaryEncoder, BinaryDecoder { protected boolean containsAlphabetOrPad(final byte[] arrayOctet) { if (arrayOctet == null) { return false; } for (final byte element : arrayOctet) { if (pad == element || isInAlphabet(element)) { return true; } } return false; } protected BaseNCodec(final int unenco...
@Test public void testContainsAlphabetOrPad() { assertFalse(codec.containsAlphabetOrPad(null)); assertFalse(codec.containsAlphabetOrPad(new byte[]{})); assertTrue(codec.containsAlphabetOrPad("OK".getBytes())); assertTrue(codec.containsAlphabetOrPad("OK ".getBytes())); assertFalse(codec.containsAlphabetOrPad("ok ".getBy...
Base64 extends BaseNCodec { public static boolean isBase64(final byte octet) { return octet == PAD_DEFAULT || (octet >= 0 && octet < DECODE_TABLE.length && DECODE_TABLE[octet] != -1); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); B...
@Test public void testIsStringBase64() { final String nullString = null; final String emptyString = ""; final String validString = "abc===defg\n\r123456\r789\r\rABC\n\nDEF==GHI\r\nJKL=============="; final String invalidString = validString + (char)0; try { Base64.isBase64(nullString); fail("Base64.isStringBase64() sho...
EqualsOp extends Param1Op { @Override public String keyword() { return "Equals"; } @Override String keyword(); @Override String operator(); }
@Test public void test() throws Exception { Op op = new EqualsOp(); assertThat(op.keyword(), equalTo("Equals")); assertThat(op.paramCount(), equalTo(1)); assertThat(op.render("id", new String[] {":1"}), equalTo("id = :1")); }
Base64 extends BaseNCodec { public Base64() { this(0); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe); boolean isUrlSafe(); @Deprecated static boolean i...
@Test public void testBase64() { final String content = "Hello World"; String encodedContent; byte[] encodedBytes = Base64.encodeBase64(StringUtils.getBytesUtf8(content)); encodedContent = StringUtils.newStringUtf8(encodedBytes); assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent); Base64 b64 = new...
Base64 extends BaseNCodec { public static byte[] decodeBase64(final String base64String) { return new Base64().decode(base64String); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLength, final byte[] lineSepara...
@Test public void testDecodeWithInnerPad() { final String content = "SGVsbG8gV29ybGQ=SGVsbG8gV29ybGQ="; final byte[] result = Base64.decodeBase64(content); final byte[] shouldBe = StringUtils.getBytesUtf8("Hello World"); assertTrue("decode should halt at pad (=)", Arrays.equals(result, shouldBe)); } @Test public void t...
Base64 extends BaseNCodec { public static byte[] encodeBase64(final byte[] binaryData) { return encodeBase64(binaryData, false); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLength, final byte[] lineSeparator,...
@Test public void testChunkedEncodeMultipleOf76() { final byte[] expectedEncode = Base64.encodeBase64(Base64TestData.DECODED, true); final String actualResult = Base64TestData.ENCODED_76_CHARS_PER_LINE.replaceAll("\n", "\r\n"); final byte[] actualEncode = StringUtils.getBytesUtf8(actualResult); assertTrue("chunkedEncod...
Base64 extends BaseNCodec { public static byte[] encodeInteger(final BigInteger bigInt) { if (bigInt == null) { throw new NullPointerException("encodeInteger called with null parameter"); } return encodeBase64(toIntegerBytes(bigInt), false); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Ba...
@Test public void testCodeIntegerNull() { try { Base64.encodeInteger(null); fail("Exception not thrown when passing in null to encodeInteger(BigInteger)"); } catch (final NullPointerException npe) { } catch (final Exception e) { fail("Incorrect Exception caught when passing in null to encodeInteger(BigInteger)"); } }
Base64 extends BaseNCodec { @Override void encode(final byte[] in, int inPos, final int inAvail, final Context context) { if (context.eof) { return; } if (inAvail < 0) { context.eof = true; if (0 == context.modulus && lineLength == 0) { return; } final byte[] buffer = ensureBufferSize(encodeSize, context); final int sa...
@Test public void testConstructor_Int_ByteArray_Boolean() { final Base64 base64 = new Base64(65, new byte[]{'\t'}, false); final byte[] encoded = base64.encode(Base64TestData.DECODED); String expectedResult = Base64TestData.ENCODED_64_CHARS_PER_LINE; expectedResult = expectedResult.replace('\n', '\t'); final String res...
CustomQueryBuilder extends AbstractCustomBuilder { @Override public String buildSql() { String s1 = Joiner.on(", ").join(columns); return String.format(SQL_TEMPLATE, s1, tailOfSql); } CustomQueryBuilder(List<String> columns, String tailOfSql); @Override String buildSql(); }
@Test public void buildSql() throws Exception { List<String> columns = Lists.newArrayList("id2", "user_name", "user_age"); CustomQueryBuilder b = new CustomQueryBuilder(columns, "where id = :1"); assertThat(b.buildSql(), equalTo("select id2, user_name, user_age from #table where id = :1")); }
Base64 extends BaseNCodec { @Deprecated public static boolean isArrayByteBase64(final byte[] arrayOctet) { return isBase64(arrayOctet); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLength, final byte[] lineSep...
@Test public void testIsArrayByteBase64() { assertFalse(Base64.isBase64(new byte[]{Byte.MIN_VALUE})); assertFalse(Base64.isBase64(new byte[]{-125})); assertFalse(Base64.isBase64(new byte[]{-10})); assertFalse(Base64.isBase64(new byte[]{0})); assertFalse(Base64.isBase64(new byte[]{64, Byte.MAX_VALUE})); assertFalse(Base...
Base64 extends BaseNCodec { public boolean isUrlSafe() { return this.encodeTable == URL_SAFE_ENCODE_TABLE; } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe...
@Test public void testIsUrlSafe() { final Base64 base64Standard = new Base64(false); final Base64 base64URLSafe = new Base64(true); assertFalse("Base64.isUrlSafe=false", base64Standard.isUrlSafe()); assertTrue("Base64.isUrlSafe=true", base64URLSafe.isUrlSafe()); final byte[] whiteSpace = {' ', '\n', '\r', '\t'}; assert...
Base64 extends BaseNCodec { @Override void decode(final byte[] in, int inPos, final int inAvail, final Context context) { if (context.eof) { return; } if (inAvail < 0) { context.eof = true; } for (int i = 0; i < inAvail; i++) { final byte[] buffer = ensureBufferSize(decodeSize, context); final byte b = in[inPos++]; if ...
@Test public void testObjectDecodeWithInvalidParameter() throws Exception { final Base64 b64 = new Base64(); try { b64.decode(Integer.valueOf(5)); fail("decode(Object) didn't throw an exception when passed an Integer object"); } catch (final DecoderException e) { } }
CustomCountBuilder extends AbstractCustomBuilder { @Override public String buildSql() { return String.format(SQL_TEMPLATE, tailOfSql); } CustomCountBuilder(String tailOfSql); @Override String buildSql(); }
@Test public void buildSql() throws Exception { CustomCountBuilder b = new CustomCountBuilder("where id = :1"); assertThat(b.buildSql(), equalTo("select count(1) from #table where id = :1")); }
Base64 extends BaseNCodec { public static String encodeBase64String(final byte[] binaryData) { return StringUtils.newStringUtf8(encodeBase64(binaryData, false)); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLe...
@Test public void testRfc4648Section10Encode() { assertEquals("", Base64.encodeBase64String(StringUtils.getBytesUtf8(""))); assertEquals("Zg==", Base64.encodeBase64String(StringUtils.getBytesUtf8("f"))); assertEquals("Zm8=", Base64.encodeBase64String(StringUtils.getBytesUtf8("fo"))); assertEquals("Zm9v", Base64.encodeB...
Base64 extends BaseNCodec { public static byte[] encodeBase64Chunked(final byte[] binaryData) { return encodeBase64(binaryData, true); } Base64(); Base64(final boolean urlSafe); Base64(final int lineLength); Base64(final int lineLength, final byte[] lineSeparator); Base64(final int lineLength, final byte[] lineSepa...
@Test public void testSingletonsChunked() { assertEquals("AA==\r\n", new String(Base64.encodeBase64Chunked(new byte[]{(byte) 0}))); assertEquals("AQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[]{(byte) 1}))); assertEquals("Ag==\r\n", new String(Base64.encodeBase64Chunked(new byte[]{(byte) 2}))); assertEquals...
BinaryCodec implements BinaryDecoder, BinaryEncoder { @Override public Object decode(final Object ascii) throws DecoderException { if (ascii == null) { return EMPTY_BYTE_ARRAY; } if (ascii instanceof byte[]) { return fromAscii((byte[]) ascii); } if (ascii instanceof char[]) { return fromAscii((char[]) ascii); } if (asc...
@Test public void testDecodeObjectException() { try { this.instance.decode(new Object()); } catch (final DecoderException e) { return; } fail("Expected DecoderException"); } @Test public void testDecodeByteArray() { byte[] bits = new byte[1]; byte[] decoded = instance.decode("00000000".getBytes(Charsets.UTF_8)); assert...
BinaryCodec implements BinaryDecoder, BinaryEncoder { public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); } @Override byte[] encode(final byte[] raw); @Override Object encode(final Object raw); @Override Object decode(final Object ascii...
@Test public void testToByteArrayFromString() { byte[] bits = new byte[1]; byte[] decoded = instance.toByteArray("00000000"); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0; decoded = instance.toByteArray("00000001"); assertEquals(new String(bits), new String(decoded)); bits = ...
BinaryCodec implements BinaryDecoder, BinaryEncoder { public static byte[] fromAscii(final char[] ascii) { if (ascii == null || ascii.length == 0) { return EMPTY_BYTE_ARRAY; } final byte[] l_raw = new byte[ascii.length >> 3]; for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) { for (int bits = 0;...
@Test public void testFromAsciiCharArray() { assertEquals(0, BinaryCodec.fromAscii((char[]) null).length); assertEquals(0, BinaryCodec.fromAscii(new char[0]).length); byte[] bits = new byte[1]; byte[] decoded = BinaryCodec.fromAscii("00000000".toCharArray()); assertEquals(new String(bits), new String(decoded)); bits = ...
CustomDeleteBuilder extends AbstractCustomBuilder { @Override public String buildSql() { return String.format(SQL_TEMPLATE, tailOfSql); } CustomDeleteBuilder(String tailOfSql); @Override String buildSql(); }
@Test public void buildSql() throws Exception { CustomDeleteBuilder b = new CustomDeleteBuilder("where id = :1"); assertThat(b.buildSql(), equalTo("delete from #table where id = :1")); }
BinaryCodec implements BinaryDecoder, BinaryEncoder { @Override public byte[] encode(final byte[] raw) { return toAsciiBytes(raw); } @Override byte[] encode(final byte[] raw); @Override Object encode(final Object raw); @Override Object decode(final Object ascii); @Override byte[] decode(final byte[] ascii); byte[] toB...
@Test public void testEncodeByteArray() { byte[] bits = new byte[1]; String l_encoded = new String(instance.encode(bits)); assertEquals("00000000", l_encoded); bits = new byte[1]; bits[0] = BIT_0; l_encoded = new String(instance.encode(bits)); assertEquals("00000001", l_encoded); bits = new byte[1]; bits[0] = BIT_0 | B...
BinaryCodec implements BinaryDecoder, BinaryEncoder { public static byte[] toAsciiBytes(final byte[] raw) { if (isEmpty(raw)) { return EMPTY_BYTE_ARRAY; } final byte[] l_ascii = new byte[raw.length << 3]; for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) { for (int bits = 0; bits < BITS.length; ...
@Test public void testToAsciiBytes() { byte[] bits = new byte[1]; String l_encoded = new String(BinaryCodec.toAsciiBytes(bits)); assertEquals("00000000", l_encoded); bits = new byte[1]; bits[0] = BIT_0; l_encoded = new String(BinaryCodec.toAsciiBytes(bits)); assertEquals("00000001", l_encoded); bits = new byte[1]; bits...
BinaryCodec implements BinaryDecoder, BinaryEncoder { public static char[] toAsciiChars(final byte[] raw) { if (isEmpty(raw)) { return EMPTY_CHAR_ARRAY; } final char[] l_ascii = new char[raw.length << 3]; for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) { for (int bits = 0; bits < BITS.length; ...
@Test public void testToAsciiChars() { byte[] bits = new byte[1]; String l_encoded = new String(BinaryCodec.toAsciiChars(bits)); assertEquals("00000000", l_encoded); bits = new byte[1]; bits[0] = BIT_0; l_encoded = new String(BinaryCodec.toAsciiChars(bits)); assertEquals("00000001", l_encoded); bits = new byte[1]; bits...
BinaryCodec implements BinaryDecoder, BinaryEncoder { public static String toAsciiString(final byte[] raw) { return new String(toAsciiChars(raw)); } @Override byte[] encode(final byte[] raw); @Override Object encode(final Object raw); @Override Object decode(final Object ascii); @Override byte[] decode(final byte[] as...
@Test public void testToAsciiString() { byte[] bits = new byte[1]; String l_encoded = BinaryCodec.toAsciiString(bits); assertEquals("00000000", l_encoded); bits = new byte[1]; bits[0] = BIT_0; l_encoded = BinaryCodec.toAsciiString(bits); assertEquals("00000001", l_encoded); bits = new byte[1]; bits[0] = BIT_0 | BIT_1; ...
Hex implements BinaryEncoder, BinaryDecoder { @Override public String toString() { return super.toString() + "[charsetName=" + this.charset + "]"; } Hex(); Hex(final Charset charset); Hex(final String charsetName); static byte[] decodeHex(final char[] data); static char[] encodeHex(final byte[] data); static char[] e...
@Test public void testCustomCharsetToString() { assertTrue(new Hex().toString().indexOf(Hex.DEFAULT_CHARSET_NAME) >= 0); }
Hex implements BinaryEncoder, BinaryDecoder { @Override public byte[] decode(final byte[] array) throws DecoderException { return decodeHex(new String(array, getCharset()).toCharArray()); } Hex(); Hex(final Charset charset); Hex(final String charsetName); static byte[] decodeHex(final char[] data); static char[] enco...
@Test public void testDecodeArrayOddCharacters() { try { new Hex().decode(new byte[]{65}); fail("An exception wasn't thrown when trying to decode an odd number of characters"); } catch (final DecoderException e) { } } @Test public void testDecodeBadCharacterPos0() { try { new Hex().decode("q0"); fail("An exception wasn...
CommonGetBuilder extends AbstractCommonBuilder { @Override public String buildSql() { String s1 = Joiner.on(", ").join(columns); return isBatch ? String.format(BATCH_SQL_TEMPLATE, s1, columnId) : String.format(SQL_TEMPLATE, s1, columnId); } CommonGetBuilder(String colId, List<String> cols, boolean isBatch); @Override S...
@Test public void build() throws Exception { List<String> columns = Lists.newArrayList("id2", "user_name", "user_age"); CommonGetBuilder b = new CommonGetBuilder("id2", columns, false); assertThat(b.buildSql(), equalTo("select id2, user_name, user_age from #table where id2 = :1")); b = new CommonGetBuilder("id2", colum...
Hex implements BinaryEncoder, BinaryDecoder { @Override public byte[] encode(final byte[] array) { return encodeHexString(array).getBytes(this.getCharset()); } Hex(); Hex(final Charset charset); Hex(final String charsetName); static byte[] decodeHex(final char[] data); static char[] encodeHex(final byte[] data); stat...
@Test public void testEncodeClassCastException() { try { new Hex().encode(new int[]{65}); fail("An exception wasn't thrown when trying to encode."); } catch (final EncoderException e) { } }
Hex implements BinaryEncoder, BinaryDecoder { public static char[] encodeHex(final byte[] data) { return encodeHex(data, true); } Hex(); Hex(final Charset charset); Hex(final String charsetName); static byte[] decodeHex(final char[] data); static char[] encodeHex(final byte[] data); static char[] encodeHex(final byte...
@Test public void testEncodeZeroes() { final char[] c = Hex.encodeHex(new byte[36]); assertEquals("000000000000000000000000000000000000000000000000000000000000000000000000", new String(c)); } @Test public void testHelloWorldLowerCaseHex() { final byte[] b = StringUtils.getBytesUtf8("Hello World"); final String expected...
Base32 extends BaseNCodec { @Override void encode(final byte[] in, int inPos, final int inAvail, final Context context) { if (context.eof) { return; } if (inAvail < 0) { context.eof = true; if (0 == context.modulus && lineLength == 0) { return; } final byte[] buffer = ensureBufferSize(encodeSize, context); final int sa...
@Test public void testSingleCharEncoding() { for (int i = 0; i < 20; i++) { Base32 codec = new Base32(); final BaseNCodec.Context context = new BaseNCodec.Context(); final byte unencoded[] = new byte[i]; final byte allInOne[] = codec.encode(unencoded); codec = new Base32(); for (int j=0; j< unencoded.length; j++) { cod...
QuotedPrintableCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { @Override public byte[] decode(final byte[] bytes) throws DecoderException { return decodeQuotedPrintable(bytes); } QuotedPrintableCodec(); QuotedPrintableCodec(final boolean strict); QuotedPrintableCodec(final Charset charse...
@Test public void testDecodeInvalid() throws Exception { final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec(); try { qpcodec.decode("="); fail("DecoderException should have been thrown"); } catch (final DecoderException e) { } try { qpcodec.decode("=A"); fail("DecoderException should have been thrown"); } ca...
CommonDeleteBuilder extends AbstractCommonBuilder { @Override public String buildSql() { return String.format(SQL_TEMPLATE, columnId); } CommonDeleteBuilder(String colId); @Override String buildSql(); }
@Test public void build() throws Exception { CommonDeleteBuilder b = new CommonDeleteBuilder("id2"); assertThat(b.buildSql(), equalTo("delete from #table where id2 = :1")); }
QuotedPrintableCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { @Override public byte[] encode(final byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes, strict); } QuotedPrintableCodec(); QuotedPrintableCodec(final boolean strict); QuotedPrintableCodec(final Charset chars...
@Test public void testEncodeNull() throws Exception { final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec(); final byte[] plain = null; final byte[] encoded = qpcodec.encode(plain); assertEquals("Encoding a null string should return null", null, encoded); } @Test public void testEncodeStringWithNull() throws ...
QuotedPrintableCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { public static final byte[] decodeQuotedPrintable(final byte[] bytes) throws DecoderException { if (bytes == null) { return null; } final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); for (int i = 0; i < bytes.leng...
@Test public void testDecodeWithNullArray() throws Exception { final byte[] plain = null; final byte[] result = QuotedPrintableCodec.decodeQuotedPrintable( plain ); assertEquals("Result should be null", null, result); }
CommonUpdateBuilder extends AbstractCommonBuilder { @Override public String buildSql() { List<String> exps = new ArrayList<String>(); for (int i = 0; i < properties.size(); i++) { String exp = columns.get(i) + " = :" + properties.get(i); exps.add(exp); } String s1 = Joiner.on(", ").join(exps); String s2 = columnId + " ...
@Test public void build() throws Exception { List<String> properties = Lists.newArrayList("id", "userName", "userAge"); List<String> columns = Lists.newArrayList("id", "user_name", "user_age"); CommonUpdateBuilder b = new CommonUpdateBuilder("id", properties, columns); assertThat(b.buildSql(), equalTo("update #table se...
URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { @Override public byte[] decode(final byte[] bytes) throws DecoderException { return decodeUrl(bytes); } URLCodec(); URLCodec(final String charset); static final byte[] encodeUrl(BitSet urlsafe, final byte[] bytes); static final byte[] dec...
@Test public void testDecodeInvalid() throws Exception { final URLCodec urlCodec = new URLCodec(); try { urlCodec.decode("%"); fail("DecoderException should have been thrown"); } catch (final DecoderException e) { } try { urlCodec.decode("%A"); fail("DecoderException should have been thrown"); } catch (final DecoderExc...
URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { @Override public byte[] encode(final byte[] bytes) { return encodeUrl(WWW_FORM_URL, bytes); } URLCodec(); URLCodec(final String charset); static final byte[] encodeUrl(BitSet urlsafe, final byte[] bytes); static final byte[] decodeUrl(fin...
@Test public void testEncodeNull() throws Exception { final URLCodec urlCodec = new URLCodec(); final byte[] plain = null; final byte[] encoded = urlCodec.encode(plain); assertEquals("Encoding a null string should return null", null, encoded); this.validateState(urlCodec); } @Test public void testEncodeStringWithNull()...
URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { public static final byte[] decodeUrl(final byte[] bytes) throws DecoderException { if (bytes == null) { return null; } final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); for (int i = 0; i < bytes.length; i++) { final int b =...
@Test public void testDecodeWithNullArray() throws Exception { final byte[] plain = null; final byte[] result = URLCodec.decodeUrl( plain ); assertEquals("Result should be null", null, result); }
QCodec extends RFC1522Codec implements StringEncoder, StringDecoder { public String encode(final String str, final Charset charset) throws EncoderException { if (str == null) { return null; } return encodeText(str, charset); } QCodec(); QCodec(final Charset charset); QCodec(final String charsetName); String encode(fi...
@Test public void testEncodeStringWithNull() throws Exception { final QCodec qcodec = new QCodec(); final String test = null; final String result = qcodec.encode( test, "charset" ); assertEquals("Result should be null", null, result); } @Test public void testEncodeObjects() throws Exception { final QCodec qcodec = new ...
CommonAddBuilder extends AbstractCommonBuilder { @Override public String buildSql() { String s1 = Joiner.on(", ").join(columns); List<String> cps = new ArrayList<String>(); for (String prop : properties) { cps.add(":" + prop); } String s2 = Joiner.on(", ").join(cps); return String.format(SQL_TEMPLATE, s1, s2); } Common...
@Test public void build() throws Exception { List<String> properties = Lists.newArrayList("id", "name", "age"); List<String> columns = Lists.newArrayList("id2", "name2", "age2"); CommonAddBuilder b = new CommonAddBuilder("id", properties, columns, true); assertThat(b.buildSql(), equalTo("insert into #table(name2, age2)...
Reflection { public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException { if (clazz.isInterface()) { throw new BeanInstantiationException(clazz, "specified class is an interface"); } try { return clazz.newInstance(); } catch (InstantiationException e) { throw new BeanInstantiationException(clazz,...
@Test public void testInstantiate() throws Exception { Reflection.instantiateClass(A.class); }
QCodec extends RFC1522Codec implements StringEncoder, StringDecoder { @Override public String decode(final String str) throws DecoderException { if (str == null) { return null; } try { return decodeText(str); } catch (final UnsupportedEncodingException e) { throw new DecoderException(e.getMessage(), e); } } QCodec(); ...
@Test public void testDecodeStringWithNull() throws Exception { final QCodec qcodec = new QCodec(); final String test = null; final String result = qcodec.decode( test ); assertEquals("Result should be null", null, result); } @Test public void testDecodeObjects() throws Exception { final QCodec qcodec = new QCodec(); f...
BCodec extends RFC1522Codec implements StringEncoder, StringDecoder { public String encode(final String value, final Charset charset) throws EncoderException { if (value == null) { return null; } return encodeText(value, charset); } BCodec(); BCodec(final Charset charset); BCodec(final String charsetName); String enc...
@Test public void testEncodeStringWithNull() throws Exception { final BCodec bcodec = new BCodec(); final String test = null; final String result = bcodec.encode(test, "charset"); assertEquals("Result should be null", null, result); } @Test public void testEncodeObjects() throws Exception { final BCodec bcodec = new BC...
BCodec extends RFC1522Codec implements StringEncoder, StringDecoder { @Override public String decode(final String value) throws DecoderException { if (value == null) { return null; } try { return this.decodeText(value); } catch (final UnsupportedEncodingException e) { throw new DecoderException(e.getMessage(), e); } } ...
@Test public void testDecodeStringWithNull() throws Exception { final BCodec bcodec = new BCodec(); final String test = null; final String result = bcodec.decode(test); assertEquals("Result should be null", null, result); } @Test public void testDecodeObjects() throws Exception { final BCodec bcodec = new BCodec(); fin...
DaitchMokotoffSoundex implements StringEncoder { public String soundex(final String source) { final String[] branches = soundex(source, true); final StringBuilder sb = new StringBuilder(); int index = 0; for (final String branch : branches) { sb.append(branch); if (++index < branches.length) { sb.append('|'); } } retur...
@Test public void testAccentedCharacterFolding() { Assert.assertEquals("294795", soundex("Straßburg")); Assert.assertEquals("294795", soundex("Strasburg")); Assert.assertEquals("095600", soundex("Éregon")); Assert.assertEquals("095600", soundex("Eregon")); } @Test public void testAdjacentCodes() { Assert.assertEquals("...
DaitchMokotoffSoundex implements StringEncoder { @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException( "Parameter supplied to DaitchMokotoffSoundex encode is not of type java.lang.String"); } return encode((String) obj); } DaitchMokotoffSo...
@Test public void testEncodeIgnoreTrimmable() { Assert.assertEquals("746536", encode(" \t\n\r Washington \t\n\r ")); Assert.assertEquals("746536", encode("Washington")); }
CommonGetAllBuilder extends AbstractCommonBuilder { @Override public String buildSql() { String s1 = Joiner.on(", ").join(columns); return String.format(SQL, s1, s1); } CommonGetAllBuilder(List<String> cols); @Override String buildSql(); }
@Test public void build() throws Exception { List<String> columns = Lists.newArrayList("id2", "user_name", "user_age"); CommonGetAllBuilder b = new CommonGetAllBuilder(columns); assertThat(b.buildSql(), equalTo("select id2, user_name, user_age from #table")); }
ColognePhonetic implements StringEncoder { public boolean isEncodeEqual(final String text1, final String text2) { return colognePhonetic(text1).equals(colognePhonetic(text2)); } String colognePhonetic(String text); @Override Object encode(final Object object); @Override String encode(final String text); boolean isEnco...
@Test public void testIsEncodeEquals() { final String[][] data = { {"Meyer", "M\u00fcller"}, {"Meyer", "Mayr"}, {"house", "house"}, {"House", "house"}, {"Haus", "house"}, {"ganz", "Gans"}, {"ganz", "G\u00e4nse"}, {"Miyagi", "Miyako"}}; for (final String[] element : data) { this.getStringEncoder().isEncodeEqual(element[...
RefinedSoundex implements StringEncoder { public int difference(final String s1, final String s2) throws EncoderException { return SoundexUtils.difference(this, s1, s2); } RefinedSoundex(); RefinedSoundex(final char[] mapping); RefinedSoundex(final String mapping); int difference(final String s1, final String s2); @O...
@Test public void testDifference() throws EncoderException { assertEquals(0, this.getStringEncoder().difference(null, null)); assertEquals(0, this.getStringEncoder().difference("", "")); assertEquals(0, this.getStringEncoder().difference(" ", " ")); assertEquals(6, this.getStringEncoder().difference("Smith", "Smythe"))...
RefinedSoundex implements StringEncoder { @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to RefinedSoundex encode is not of type java.lang.String"); } return soundex((String) obj); } RefinedSoundex(); RefinedSoun...
@Test public void testEncode() { assertEquals("T6036084", this.getStringEncoder().encode("testing")); assertEquals("T6036084", this.getStringEncoder().encode("TESTING")); assertEquals("T60", this.getStringEncoder().encode("The")); assertEquals("Q503", this.getStringEncoder().encode("quick")); assertEquals("B1908", this...
RefinedSoundex implements StringEncoder { char getMappingCode(final char c) { if (!Character.isLetter(c)) { return 0; } return this.soundexMapping[Character.toUpperCase(c) - 'A']; } RefinedSoundex(); RefinedSoundex(final char[] mapping); RefinedSoundex(final String mapping); int difference(final String s1, final Stri...
@Test public void testGetMappingCodeNonLetter() { final char code = this.getStringEncoder().getMappingCode('#'); assertEquals("Code does not equals zero", 0, code); }
RefinedSoundex implements StringEncoder { public String soundex(String str) { if (str == null) { return null; } str = SoundexUtils.clean(str); if (str.length() == 0) { return str; } final StringBuilder sBuf = new StringBuilder(); sBuf.append(str.charAt(0)); char last, current; last = '*'; for (int i = 0; i < str.length...
@Test public void testNewInstance() { assertEquals("D6043", new RefinedSoundex().soundex("dogs")); } @Test public void testNewInstance2() { assertEquals("D6043", new RefinedSoundex(RefinedSoundex.US_ENGLISH_MAPPING_STRING.toCharArray()).soundex("dogs")); } @Test public void testNewInstance3() { assertEquals("D6043", ne...
PhoneticEngine { public String encode(final String input) { final Languages.LanguageSet languageSet = this.lang.guessLanguages(input); return encode(input, languageSet); } PhoneticEngine(final NameType nameType, final RuleType ruleType, final boolean concat); PhoneticEngine(final NameType nameType, final RuleType rule...
@Test(timeout = 10000L) public void testEncode() { final PhoneticEngine engine = new PhoneticEngine(this.nameType, this.ruleType, this.concat, this.maxPhonemes); final String phoneticActual = engine.encode(this.name); assertEquals("phoneme incorrect", this.phoneticExpected, phoneticActual); if (this.concat) { final Str...
BeiderMorseEncoder implements StringEncoder { @Override public Object encode(final Object source) throws EncoderException { if (!(source instanceof String)) { throw new EncoderException("BeiderMorseEncoder encode parameter is not of type String"); } return encode((String) source); } @Override Object encode(final Objec...
@Test public void testAllChars() throws EncoderException { final BeiderMorseEncoder bmpm = createGenericApproxEncoder(); for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) { bmpm.encode(Character.toString(c)); } } @Test public void testEncodeGna() throws EncoderException { final BeiderMorseEncoder bmpm = ...
BeiderMorseEncoder implements StringEncoder { public void setConcat(final boolean concat) { this.engine = new PhoneticEngine(this.engine.getNameType(), this.engine.getRuleType(), concat, this.engine.getMaxPhonemes()); } @Override Object encode(final Object source); @Override String encode(final String source); NameTyp...
@Test public void testSetConcat() { final BeiderMorseEncoder bmpm = new BeiderMorseEncoder(); bmpm.setConcat(false); assertFalse("Should be able to set concat to false", bmpm.isConcat()); }
BeiderMorseEncoder implements StringEncoder { public void setRuleType(final RuleType ruleType) { this.engine = new PhoneticEngine(this.engine.getNameType(), ruleType, this.engine.isConcat(), this.engine.getMaxPhonemes()); } @Override Object encode(final Object source); @Override String encode(final String source); Nam...
@Test(expected = IllegalArgumentException.class) public void testSetRuleTypeToRulesIllegalArgumentException() { final BeiderMorseEncoder bmpm = new BeiderMorseEncoder(); bmpm.setRuleType(RuleType.RULES); }
Metaphone implements StringEncoder { public Metaphone() { super(); } Metaphone(); String metaphone(final String txt); @Override Object encode(final Object obj); @Override String encode(final String str); boolean isMetaphoneEqual(final String str1, final String str2); int getMaxCodeLen(); void setMaxCodeLen(final int ma...
@Test public void testMetaphone() { assertEquals("HL", this.getStringEncoder().metaphone("howl")); assertEquals("TSTN", this.getStringEncoder().metaphone("testing")); assertEquals("0", this.getStringEncoder().metaphone("The")); assertEquals("KK", this.getStringEncoder().metaphone("quick")); assertEquals("BRN", this.get...
DoubleMetaphone implements StringEncoder { public boolean isDoubleMetaphoneEqual(final String value1, final String value2) { return isDoubleMetaphoneEqual(value1, value2, false); } DoubleMetaphone(); String doubleMetaphone(final String value); String doubleMetaphone(String value, final boolean alternate); @Override Obj...
@Test public void testCCedilla() { assertTrue(this.getStringEncoder().isDoubleMetaphoneEqual("\u00e7", "S")); } @Test public void testCodec184() throws Throwable { assertTrue(new DoubleMetaphone().isDoubleMetaphoneEqual("", "", false)); assertTrue(new DoubleMetaphone().isDoubleMetaphoneEqual("", "", true)); assertFalse...
DoubleMetaphone implements StringEncoder { public DoubleMetaphone() { super(); } DoubleMetaphone(); String doubleMetaphone(final String value); String doubleMetaphone(String value, final boolean alternate); @Override Object encode(final Object obj); @Override String encode(final String value); boolean isDoubleMetaphone...
@Test public void testDoubleMetaphone() { assertDoubleMetaphone("TSTN", "testing"); assertDoubleMetaphone("0", "The"); assertDoubleMetaphone("KK", "quick"); assertDoubleMetaphone("PRN", "brown"); assertDoubleMetaphone("FKS", "fox"); assertDoubleMetaphone("JMPT", "jumped"); assertDoubleMetaphone("AFR", "over"); assertDo...
Nysiis implements StringEncoder { @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to Nysiis encode is not of type java.lang.String"); } return this.nysiis((String) obj); } Nysiis(); Nysiis(final boolean strict); @...
@Test public void testTrueVariant() { final Nysiis encoder = new Nysiis(true); final String encoded = encoder.encode("WESTERLUND"); Assert.assertTrue(encoded.length() <= 6); Assert.assertEquals("WASTAR", encoded); }
MatchRatingApproachEncoder implements StringEncoder { String removeAccents(final String accentedWord) { if (accentedWord == null) { return null; } final StringBuilder sb = new StringBuilder(); final int n = accentedWord.length(); for (int i = 0; i < n; i++) { final char c = accentedWord.charAt(i); final int pos = UNICO...
@Test public final void testAccentRemoval_AllLower_SuccessfullyRemoved() { assertEquals("aeiou", this.getStringEncoder().removeAccents("áéíóú")); } @Test public final void testAccentRemoval_WithSpaces_SuccessfullyRemovedAndSpacesInvariant() { assertEquals("ae io u", this.getStringEncoder().removeAccents("áé íó ú")); } ...
MatchRatingApproachEncoder implements StringEncoder { String removeDoubleConsonants(final String name) { String replacedName = name.toUpperCase(); for (final String dc : DOUBLE_CONSONANT) { if (replacedName.contains(dc)) { final String singleLetter = dc.substring(0, 1); replacedName = replacedName.replace(dc, singleLet...
@Test public final void testRemoveSingleDoubleConsonants_BUBLE_RemovedSuccessfully() { assertEquals("BUBLE", this.getStringEncoder().removeDoubleConsonants("BUBBLE")); } @Test public final void testRemoveDoubleConsonants_MISSISSIPPI_RemovedSuccessfully() { assertEquals("MISISIPI", this.getStringEncoder().removeDoubleCo...
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } @Override final Object encode(final Object pObject); @Overr...
@Test public final void testIsVowel_CapitalA_ReturnsTrue() { assertTrue(this.getStringEncoder().isVowel("A")); } @Test public final void testIsVowel_SmallD_ReturnsFalse() { assertFalse(this.getStringEncoder().isVowel("d")); } @Test public final void testisVowel_SingleVowel_ReturnsTrue() { assertTrue(this.getStringEncod...
MatchRatingApproachEncoder implements StringEncoder { String removeVowels(String name) { final String firstLetter = name.substring(0, 1); name = name.replaceAll("A", EMPTY); name = name.replaceAll("E", EMPTY); name = name.replaceAll("I", EMPTY); name = name.replaceAll("O", EMPTY); name = name.replaceAll("U", EMPTY); na...
@Test public final void testRemoveVowel_ALESSANDRA_Returns_ALSSNDR() { assertEquals("ALSSNDR", this.getStringEncoder().removeVowels("ALESSANDRA")); } @Test public final void testRemoveVowel__AIDAN_Returns_ADN() { assertEquals("ADN", this.getStringEncoder().removeVowels("AIDAN")); } @Test public final void testRemoveVow...
MatchRatingApproachEncoder implements StringEncoder { String getFirst3Last3(final String name) { final int nameLength = name.length(); if (nameLength > SIX) { final String firstThree = name.substring(0, THREE); final String lastThree = name.substring(nameLength - THREE, nameLength); return firstThree + lastThree; } els...
@Test public final void testGetFirstLast3__ALEXANDER_Returns_Aleder() { assertEquals("Aleder", this.getStringEncoder().getFirst3Last3("Alexzander")); } @Test public final void testGetFirstLast3_PETE_Returns_PETE() { assertEquals("PETE", this.getStringEncoder().getFirst3Last3("PETE")); }
MatchRatingApproachEncoder implements StringEncoder { int leftToRightThenRightToLeftProcessing(final String name1, final String name2) { final char[] name1Char = name1.toCharArray(); final char[] name2Char = name2.toCharArray(); final int name1Size = name1.length() - 1; final int name2Size = name2.length() - 1; String ...
@Test public final void testleftTorightThenRightToLeft_ALEXANDER_ALEXANDRA_Returns4() { assertEquals(4, this.getStringEncoder().leftToRightThenRightToLeftProcessing("ALEXANDER", "ALEXANDRA")); } @Test public final void testleftTorightThenRightToLeft_EINSTEIN_MICHAELA_Returns0() { assertEquals(0, this.getStringEncoder()...
MatchRatingApproachEncoder implements StringEncoder { int getMinRating(final int sumLength) { int minRating = 0; if (sumLength <= FOUR) { minRating = FIVE; } else if (sumLength >= FIVE && sumLength <= SEVEN) { minRating = FOUR; } else if (sumLength >= EIGHT && sumLength <= ELEVEN) { minRating = THREE; } else if (sumLen...
@Test public final void testGetMinRating_7_Return4_Successfully() { assertEquals(4, this.getStringEncoder().getMinRating(7)); } @Test public final void testGetMinRating_1_Returns5_Successfully() { assertEquals(5, this.getStringEncoder().getMinRating(1)); } @Test public final void testGetMinRating_2_Returns5_Successfull...
MatchRatingApproachEncoder implements StringEncoder { String cleanName(final String name) { String upperName = name.toUpperCase(Locale.ENGLISH); final String[] charsToTrim = { "\\-", "[&]", "\\'", "\\.", "[\\,]" }; for (final String str : charsToTrim) { upperName = upperName.replaceAll(str, EMPTY); } upperName = remove...
@Test public final void testcleanName_SuccessfullyClean() { assertEquals("THISISATEST", this.getStringEncoder().cleanName("This-ís a t.,es &t")); }
MatchRatingApproachEncoder implements StringEncoder { @Override public final Object encode(final Object pObject) throws EncoderException { if (!(pObject instanceof String)) { throw new EncoderException( "Parameter supplied to Match Rating Approach encoder is not of type java.lang.String"); } return encode((String) pObj...
@Test public final void testGetEncoding_HARPER_HRPR() { assertEquals("HRPR", this.getStringEncoder().encode("HARPER")); } @Test public final void testGetEncoding_SMITH_to_SMTH() { assertEquals("SMTH", this.getStringEncoder().encode("Smith")); } @Test public final void testGetEncoding_SMYTH_to_SMYTH() { assertEquals("SM...
Parser implements ParserTreeConstants, ParserConstants { final public void Expression() throws ParseException { ASTExpression jjtn000 = new ASTExpression(JJTEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { ConditionalOrExpression(); } catch (Throwable jjte...
@Test public void testExpression() throws Exception { String sql = "select where 1=1 #if(:1==false && :2!=null && :3==true) and id>10 #end"; ASTRootNode n = new Parser(sql).parse().init(); ParameterContext ctx = getParameterContext(Lists.newArrayList((Type) Boolean.class, Object.class, Boolean.class)); n.checkAndBind(c...
Reflection { public static Set<Annotation> getAnnotations(Class<?> clazz) { Set<Annotation> annos = new HashSet<Annotation>(); getAnnotations(clazz, annos); return annos; } static T instantiate(Class<T> clazz); static T instantiateClass(Class<T> clazz); static T instantiateClass(Constructor<T> ctor, Object... args); s...
@Test public void testGetAnnotations() throws Exception { Set<Annotation> annos = new HashSet<Annotation>(); Reflection.getAnnotations(SubDao.class, annos); assertThat(annos.size(), equalTo(1)); }
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName) { try { Optional<Long> optionalConfigId = configurationAccessor.getProviderConfigurationBy...
@Test public void getProjectsByProviderConfigNameTest() throws Exception { ConfigurationModel configurationModel = createConfigurationModel(); ProviderProjectEntity providerProjectEntity = new ProviderProjectEntity(name, description, href, projectOwnerEmail, 1L); ConfigurationAccessor configurationAccessor = Mockito.mo...
DefaultProviderTaskPropertiesAccessor implements ProviderTaskPropertiesAccessor { @Override public void setTaskProperty(Long configId, String taskName, String propertyKey, String propertyValue) throws AlertDatabaseConstraintException { if (null == configId || StringUtils.isBlank(taskName) || StringUtils.isBlank(propert...
@Test public void setTaskPropertyExceptionTest() throws Exception { DefaultProviderTaskPropertiesAccessor providerTaskPropertiesAccessor = new DefaultProviderTaskPropertiesAccessor(providerTaskPropertiesRepository); try { providerTaskPropertiesAccessor.setTaskProperty(null, "", "", ""); fail(); } catch (AlertDatabaseCo...
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptors() throws AlertDatabaseConstraintException { List<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findAll(); List<RegisteredDescriptorModel> descriptorModels = n...
@Test public void getRegisteredDescriptorsTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final DescriptorType descriptorType = DescriptorType.CHANNEL; RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId); registeredDescriptorEntity.setI...
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseC...
@Test public void getRegisteredDescriptorByKeyTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final DescriptorType descriptorType = DescriptorType.CHANNEL; RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId); registeredDescriptorEntity....
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); }...
@Test public void getRegisteredDescriptorsByTypeTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final DescriptorType descriptorType = DescriptorType.CHANNEL; RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DescriptorT...
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); return Optional.of(createRegisteredDescriptorM...
@Test public void getRegisteredDescriptorByIdTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final DescriptorType descriptorType = DescriptorType.CHANNEL; final Long descriptorId = 2L; RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId)...
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorByKey(descriptorKey); Long contextId = saveCon...
@Test public void getFieldsForDescriptorTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL; final ConfigContextEnum invalidConfigContextEnum = ConfigContextEnum.DISTRIBUTION; final String definedFieldsKey = "defined-fie...
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); Long contextId = saveContextAndR...
@Test public void getFieldsForDescriptorByIdTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL; final String definedFieldsKey = "defined-field-key-test"; Boolean isSensitive = Boolean.TRUE; final Long descriptorId = 1L;...
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName) { if (StringUtils.isBlank(providerConfigName)) { return List.of(); } try { Optional<Long> optionalProviderConfigId = configurationAccessor.getProviderConfigurati...
@Test public void getUsersByProviderConfigNameOptionalEmptyTest() throws Exception { ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); Mockito.when(configurationAccessor.getProviderConfigurationByName(Mockito.any())).thenReturn(Optional.empty()); DefaultProviderDataAccessor provid...
DefaultUserAccessor implements UserAccessor { @Override public List<UserModel> getUsers() { List<UserEntity> userList = userRepository.findAll(); return userList.stream().map(this::createModel).collect(Collectors.toList()); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepo...
@Test public void getUsersTest() { final Long authenticationTypeId = 1L; final String roleName = "userName"; UserEntity userEntity = new UserEntity(username, password, emailAddress, authenticationTypeId); userEntity.setId(1L); UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L); UserRoleModel userRoleModel...
DefaultUserAccessor implements UserAccessor { @Override public Optional<UserModel> getUser(Long userId) { return userRepository.findById(userId).map(this::createModel); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, Default...
@Test public void getUserByUserIdTest() { final Long userId = 1L; final Long emptyUserId = 5L; final Long authenticationTypeId = 1L; final String roleName = "userName"; UserEntity userEntity = new UserEntity(username, password, emailAddress, authenticationTypeId); userEntity.setId(1L); UserRoleRelation userRoleRelation...
DefaultUserAccessor implements UserAccessor { @Override public UserModel addUser(String userName, String password, String emailAddress) throws AlertDatabaseConstraintException { return addUser(UserModel.newUser(userName, password, emailAddress, AuthenticationType.DATABASE, Collections.emptySet(), true), false); } @Auto...
@Test public void addUserTest() throws Exception { final String roleName = "userName"; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); AuthenticationTypeDetails authenticationTypeDetails = new AuthenticationTypeDetails(2L, "authentication-name"); UserRoleRelation user...
DefaultUserAccessor implements UserAccessor { @Override public UserModel updateUser(UserModel user, boolean passwordEncoded) throws AlertDatabaseConstraintException { Long userId = user.getId(); if (null == userId) { throw new AlertDatabaseConstraintException("A user id must be specified"); } UserEntity existingUser = ...
@Test public void updateUserTest() throws Exception { final String roleName = "userName"; AuthenticationType authenticationType = AuthenticationType.DATABASE; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); UserRoleModel roles = createUserRoleModel(1L, roleName, true)...
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToU...
@Test public void updateProjectAndUserDataTest() { ProviderProjectEntity storedProviderProjectEntity = new ProviderProjectEntity("stored-name", "stored-description", "stored-href", "stored-Email", 2L); ProviderProject providerProject = new ProviderProject(name, description, href, projectOwnerEmail); ProviderProjectEnti...
DefaultUserAccessor implements UserAccessor { @Override public boolean assignRoles(String username, Set<Long> roleIds) { Optional<Long> optionalUserId = userRepository.findByUserName(username).map(UserEntity::getId); if (optionalUserId.isPresent()) { roleAccessor.updateUserRoles(optionalUserId.get(), roleAccessor.getRo...
@Test public void assignRolesTest() { final String badUsername = "badUsername"; final Long roleId = 5L; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity)); Mockito.when(...
DefaultUserAccessor implements UserAccessor { @Override public boolean changeUserPassword(String username, String newPassword) { Optional<UserEntity> entity = userRepository.findByUserName(username); if (entity.isPresent()) { return changeUserPassword(entity.get(), newPassword); } return false; } @Autowired DefaultUse...
@Test public void changeUserPasswordTest() { final String badUsername = "badUsername"; final String newPassword = "newPassword"; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); UserEntity newUserEntity = new UserEntity(username, newPassword, emailAddress, 2L); userEnt...
DefaultUserAccessor implements UserAccessor { @Override public boolean changeUserEmailAddress(String username, String emailAddress) { Optional<UserEntity> entity = userRepository.findByUserName(username); if (entity.isPresent()) { return changeUserEmailAddress(entity.get(), emailAddress); } return false; } @Autowired ...
@Test public void changeUserEmailAddressTest() { final String badUsername = "badUsername"; final String newEmailAddress = "newemail.noreplay@blackducksoftware.com"; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); UserEntity newUserEntity = new UserEntity(username, pas...
DefaultUserAccessor implements UserAccessor { @Override public void deleteUser(String userName) throws AlertForbiddenOperationException { Optional<UserEntity> optionalUser = userRepository.findByUserName(userName); if (optionalUser.isPresent()) { UserEntity user = optionalUser.get(); deleteUserEntity(user); } } @Autowi...
@Test public void deleteUserByNameTest() throws Exception { UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(5L); Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity)); DefaultUserAccessor defaultUserAccessor = new DefaultUser...
AzureFieldsExtractor { public <T> Optional<T> extractField(JsonObject fieldsObject, AzureFieldDefinition<T> fieldDefinition) { JsonElement foundField = fieldsObject.get(fieldDefinition.getFieldName()); if (null != foundField) { T fieldValue = gson.fromJson(foundField, fieldDefinition.getFieldType()); return Optional.of...
@Test public void extractFieldValidTest() { Gson gson = new GsonBuilder().create(); AzureFieldsExtractor azureFieldsExtractor = new AzureFieldsExtractor(gson); FieldsTestClass originalCopy = createTestClass("a value", 42, "a different value", 8675309); String jsonString = gson.toJson(originalCopy); JsonObject jsonObjec...
JiraServerProperties implements IssueTrackerServiceConfig { public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraServerRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jir...
@Test public void testServerServiceFactory() { try { JiraServerProperties properties = new JiraServerProperties("http: JiraServerServiceFactory serviceFactory = properties.createJiraServicesServerFactory(LoggerFactory.getLogger(getClass()), new Gson()); assertNotNull(serviceFactory); } catch (IssueTrackerException ex) ...
JiraServerIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { return projectService.getProjectsByName(jiraProjectName); } JiraServerIssueConfigValidator(ProjectService projectService, UserSearchServ...
@Test public void validateSuccessTest() throws IntegrationException { ProjectService projectService = Mockito.mock(ProjectService.class); UserSearchService userSearchService = Mockito.mock(UserSearchService.class); IssueTypeService issueTypeService = Mockito.mock(IssueTypeService.class); IssueMetaDataService issueMetaD...
JiraServerRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Server instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTracke...
@Test public void testContextNull() throws Exception { JiraServerRequestDelegator service = new JiraServerRequestDelegator(gson, null); List<IssueTrackerRequest> requests = new ArrayList<>(); try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Context ...