target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public final void testAccentRemoval_MixedWithUnusualChars_SuccessfullyRemovedAndUnusualcharactersInvariant() { assertEquals("A-e'i.,o&u", this.getStringEncoder().removeAccents("Á-e'í.,ó&ú")); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testAccentRemoval_ComprehensiveAccentMix_AllSuccessfullyRemoved() { assertEquals("E,E,E,E,U,U,I,I,A,A,O,e,e,e,e,u,u,i,i,a,a,o,c", this.getStringEncoder().removeAccents("È,É,Ê,Ë,Û,Ù,Ï,Î,À,Â,Ô,è,é,ê,ë,û,ù,ï,î,à,â,ô,ç")); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testAccentRemovalNormalString_NoChange() { assertEquals("Colorless green ideas sleep furiously", this.getStringEncoder().removeAccents("Colorless green ideas sleep furiously")); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testAccentRemoval_NINO_NoChange() { assertEquals("", this.getStringEncoder().removeAccents("")); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testAccentRemoval_NullValue_ReturnNullSuccessfully() { assertEquals(null, this.getStringEncoder().removeAccents(null)); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 = UNICODE.indexOf(c); if (pos > -1) { sb.append(PLAIN_ASCII.charAt(pos)); } else { sb.append(c); } } return sb.toString(); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public void testIfElseIf2() throws Exception { String sql = "select where 1=1" + "#if(:1>0)" + " and id>:1" + "#elseif(:1<0)" + " and id<:1" + "#end"; ASTRootNode n = new Parser(sql).parse().init(); ParameterContext ctx = getParameterContext(Lists.newArrayList((Type) Integer.class)); n.checkAndBind(ctx); InvocationContext context = DefaultInvocationContext.create(); context.addParameter("1", -100); n.render(context); BoundSql boundSql = context.getBoundSql(); assertThat(boundSql.getSql().toString(), equalTo("select where 1=1 and id<?")); assertThat(boundSql.getArgs(), contains(new Object[]{-100})); }
|
final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); public ParserTokenManager token_source; public Token token; public Token jj_nt; }
|
@Test public final void testRemoveSingleDoubleConsonants_BUBLE_RemovedSuccessfully() { assertEquals("BUBLE", this.getStringEncoder().removeDoubleConsonants("BUBBLE")); }
|
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, singleLetter); } } return replacedName; }
|
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, singleLetter); } } return replacedName; } }
|
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, singleLetter); } } return replacedName; } }
|
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, singleLetter); } } return replacedName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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, singleLetter); } } return replacedName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testRemoveDoubleConsonants_MISSISSIPPI_RemovedSuccessfully() { assertEquals("MISISIPI", this.getStringEncoder().removeDoubleConsonants("MISSISSIPPI")); }
|
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, singleLetter); } } return replacedName; }
|
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, singleLetter); } } return replacedName; } }
|
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, singleLetter); } } return replacedName; } }
|
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, singleLetter); } } return replacedName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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, singleLetter); } } return replacedName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testRemoveDoubleDoubleVowel_BEETLE_NotRemoved() { assertEquals("BEETLE", this.getStringEncoder().removeDoubleConsonants("BEETLE")); }
|
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, singleLetter); } } return replacedName; }
|
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, singleLetter); } } return replacedName; } }
|
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, singleLetter); } } return replacedName; } }
|
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, singleLetter); } } return replacedName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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, singleLetter); } } return replacedName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testIsVowel_CapitalA_ReturnsTrue() { assertTrue(this.getStringEncoder().isVowel("A")); }
|
boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); }
|
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } }
|
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } }
|
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); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testIsVowel_SmallD_ReturnsFalse() { assertFalse(this.getStringEncoder().isVowel("d")); }
|
boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); }
|
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } }
|
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } }
|
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); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testRemoveVowel_ALESSANDRA_Returns_ALSSNDR() { assertEquals("ALSSNDR", this.getStringEncoder().removeVowels("ALESSANDRA")); }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testRemoveVowel__AIDAN_Returns_ADN() { assertEquals("ADN", this.getStringEncoder().removeVowels("AIDAN")); }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testRemoveVowel__DECLAN_Returns_DCLN() { assertEquals("DCLN", this.getStringEncoder().removeVowels("DECLAN")); }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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); name = name.replaceAll("\\s{2,}\\b", SPACE); if (isVowel(firstLetter)) { return firstLetter + name; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetFirstLast3__ALEXANDER_Returns_Aleder() { assertEquals("Aleder", this.getStringEncoder().getFirst3Last3("Alexzander")); }
|
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; } else { return name; } }
|
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; } else { return name; } } }
|
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; } else { return name; } } }
|
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; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetFirstLast3_PETE_Returns_PETE() { assertEquals("PETE", this.getStringEncoder().getFirst3Last3("PETE")); }
|
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; } else { return name; } }
|
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; } else { return name; } } }
|
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; } else { return name; } } }
|
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; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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; } else { return name; } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public void testIfElseIfElse() throws Exception { String sql = "select where 1=1" + "#if(:1>0)" + " and id>:1" + "#elseif(:1<0)" + " and id<:1" + "#else" + " and id=:1" + "#end"; ASTRootNode n = new Parser(sql).parse().init(); ParameterContext ctx = getParameterContext(Lists.newArrayList((Type) Integer.class)); n.checkAndBind(ctx); InvocationContext context = DefaultInvocationContext.create(); context.addParameter("1", 100); n.render(context); BoundSql boundSql = context.getBoundSql(); assertThat(boundSql.getSql().toString(), equalTo("select where 1=1 and id>?")); assertThat(boundSql.getArgs(), contains(new Object[]{100})); }
|
final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); public ParserTokenManager token_source; public Token token; public Token jj_nt; }
|
@Test public final void testleftTorightThenRightToLeft_ALEXANDER_ALEXANDRA_Returns4() { assertEquals(4, this.getStringEncoder().leftToRightThenRightToLeftProcessing("ALEXANDER", "ALEXANDRA")); }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testleftTorightThenRightToLeft_EINSTEIN_MICHAELA_Returns0() { assertEquals(0, this.getStringEncoder().leftToRightThenRightToLeftProcessing("EINSTEIN", "MICHAELA")); }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 name1LtRStart = EMPTY; String name1LtREnd = EMPTY; String name2RtLStart = EMPTY; String name2RtLEnd = EMPTY; for (int i = 0; i < name1Char.length; i++) { if (i > name2Size) { break; } name1LtRStart = name1.substring(i, i + 1); name1LtREnd = name1.substring(name1Size - i, name1Size - i + 1); name2RtLStart = name2.substring(i, i + 1); name2RtLEnd = name2.substring(name2Size - i, name2Size - i + 1); if (name1LtRStart.equals(name2RtLStart)) { name1Char[i] = ' '; name2Char[i] = ' '; } if (name1LtREnd.equals(name2RtLEnd)) { name1Char[name1Size - i] = ' '; name2Char[name2Size - i] = ' '; } } final String strA = new String(name1Char).replaceAll("\\s+", EMPTY); final String strB = new String(name2Char).replaceAll("\\s+", EMPTY); if (strA.length() > strB.length()) { return Math.abs(SIX - strA.length()); } else { return Math.abs(SIX - strB.length()); } } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetMinRating_7_Return4_Successfully() { assertEquals(4, this.getStringEncoder().getMinRating(7)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetMinRating_1_Returns5_Successfully() { assertEquals(5, this.getStringEncoder().getMinRating(1)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetMinRating_2_Returns5_Successfully() { assertEquals(5, this.getStringEncoder().getMinRating(2)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testgetMinRating_5_Returns4_Successfully(){ assertEquals(4, this.getStringEncoder().getMinRating(5)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testgetMinRating_5_Returns4_Successfully2(){ assertEquals(4, this.getStringEncoder().getMinRating(5)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testgetMinRating_6_Returns4_Successfully(){ assertEquals(4, this.getStringEncoder().getMinRating(6)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testgetMinRating_7_Returns4_Successfully(){ assertEquals(4, this.getStringEncoder().getMinRating(7)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testgetMinRating_8_Returns3_Successfully(){ assertEquals(3, this.getStringEncoder().getMinRating(8)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public void testIfElseIfElse2() throws Exception { String sql = "select where 1=1" + "#if(:1>0)" + " and id>:1" + "#elseif(:1<0)" + " and id<:1" + "#else" + " and id=:1" + "#end"; ASTRootNode n = new Parser(sql).parse().init(); ParameterContext ctx = getParameterContext(Lists.newArrayList((Type) Integer.class)); n.checkAndBind(ctx); InvocationContext context = DefaultInvocationContext.create(); context.addParameter("1", -100); n.render(context); BoundSql boundSql = context.getBoundSql(); assertThat(boundSql.getSql().toString(), equalTo("select where 1=1 and id<?")); assertThat(boundSql.getArgs(), contains(new Object[]{-100})); }
|
final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); public ParserTokenManager token_source; public Token token; public Token jj_nt; }
|
@Test public final void testgetMinRating_10_Returns3_Successfully(){ assertEquals(3, this.getStringEncoder().getMinRating(10)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testgetMinRating_11_Returns_3_Successfully(){ assertEquals(3, this.getStringEncoder().getMinRating(11)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetMinRating_13_Returns_1_Successfully() { assertEquals(1, this.getStringEncoder().getMinRating(13)); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 (sumLength == TWELVE) { minRating = TWO; } else { minRating = ONE; } return minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testcleanName_SuccessfullyClean() { assertEquals("THISISATEST", this.getStringEncoder().cleanName("This-ís a t.,es &t")); }
|
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 = removeAccents(upperName); upperName = upperName.replaceAll("\\s+", EMPTY); return upperName; }
|
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 = removeAccents(upperName); upperName = upperName.replaceAll("\\s+", EMPTY); return upperName; } }
|
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 = removeAccents(upperName); upperName = upperName.replaceAll("\\s+", EMPTY); return upperName; } }
|
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 = removeAccents(upperName); upperName = upperName.replaceAll("\\s+", EMPTY); return upperName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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 = removeAccents(upperName); upperName = upperName.replaceAll("\\s+", EMPTY); return upperName; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisVowel_SingleVowel_ReturnsTrue() { assertTrue(this.getStringEncoder().isVowel(("I"))); }
|
boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); }
|
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } }
|
MatchRatingApproachEncoder implements StringEncoder { boolean isVowel(final String letter) { return letter.equalsIgnoreCase("E") || letter.equalsIgnoreCase("A") || letter.equalsIgnoreCase("O") || letter.equalsIgnoreCase("I") || letter.equalsIgnoreCase("U"); } }
|
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); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEquals_CornerCase_SecondNameNothing_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals("test", "")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEquals_CornerCase_FirstNameNothing_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals("", "test")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEquals_CornerCase_SecondNameJustSpace_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals("test", " ")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEquals_CornerCase_FirstNameJustSpace_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals(" ", "test")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEquals_CornerCase_SecondNameNull_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals("test", null)); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public void testIfElseIfElse3() throws Exception { String sql = "select where 1=1" + "#if(:1>0)" + " and id>:1" + "#elseif(:1<0)" + " and id<:1" + "#else" + " and id=:1" + "#end"; ASTRootNode n = new Parser(sql).parse().init(); ParameterContext ctx = getParameterContext(Lists.newArrayList((Type) Integer.class)); n.checkAndBind(ctx); InvocationContext context = DefaultInvocationContext.create(); context.addParameter("1", 0); n.render(context); BoundSql boundSql = context.getBoundSql(); assertThat(boundSql.getSql().toString(), equalTo("select where 1=1 and id=?")); assertThat(boundSql.getArgs(), contains(new Object[]{0})); }
|
final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); }
|
Parser implements ParserTreeConstants, ParserConstants { final public ASTRootNode parse() throws ParseException { ASTRootNode jjtn000 = new ASTRootNode(JJTROOTNODE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { DML(); ASTBlock jjtn001 = new ASTBlock(JJTBLOCK); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); jjtn001.jjtSetFirstToken(getToken(1)); try { label_1: while (true) { Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BLANK: case QUOTE_TEXT: case JDBC_ITERABLE_PARAMETER: case JDBC_PARAMETER: case GLOBAL_TABLE: case JOIN_PARAMETER: case IF_DIRECTIVE: case INSERT: case DELETE: case UPDATE: case SELECT: case REPLACE: case MERGE: case TRUNCATE: case TEXT: ; break; default: jj_la1[0] = jj_gen; break label_1; } } } catch (Throwable jjte001) { if (jjtc001) { jjtree.clearNodeScope(jjtn001); jjtc001 = false; } else { jjtree.popNode(); } if (jjte001 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte001;} } if (jjte001 instanceof ParseException) { {if (true) throw (ParseException)jjte001;} } {if (true) throw (Error)jjte001;} } finally { if (jjtc001) { jjtree.closeNodeScope(jjtn001, true); jjtn001.jjtSetLastToken(getToken(0)); } } jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } throw new Error("Missing return statement in function"); } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); public ParserTokenManager token_source; public Token token; public Token jj_nt; }
|
@Test public final void testisEncodeEquals_CornerCase_FirstNameNull_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals(null, "test")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEquals_CornerCase_FirstNameJust1Letter_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals("t", "test")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testisEncodeEqualsSecondNameJust1Letter_ReturnsFalse() { assertFalse(this.getStringEncoder().isEncodeEquals("test", "t")); }
|
public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
MatchRatingApproachEncoder implements StringEncoder { public boolean isEncodeEquals(String name1, String name2) { if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) { return false; } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) { return false; } else if (name1.length() == 1 || name2.length() == 1) { return false; } else if (name1.equalsIgnoreCase(name2)) { return true; } name1 = cleanName(name1); name2 = cleanName(name2); name1 = removeVowels(name1); name2 = removeVowels(name2); name1 = removeDoubleConsonants(name1); name2 = removeDoubleConsonants(name2); name1 = getFirst3Last3(name1); name2 = getFirst3Last3(name2); if (Math.abs(name1.length() - name2.length()) >= THREE) { return false; } final int sumLength = Math.abs(name1.length() + name2.length()); int minRating = 0; minRating = getMinRating(sumLength); final int count = leftToRightThenRightToLeftProcessing(name1, name2); return count >= minRating; } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_HARPER_HRPR() { assertEquals("HRPR", this.getStringEncoder().encode("HARPER")); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_SMITH_to_SMTH() { assertEquals("SMTH", this.getStringEncoder().encode("Smith")); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_SMYTH_to_SMYTH() { assertEquals("SMYTH", this.getStringEncoder().encode("Smyth")); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_Space_to_Nothing() { assertEquals("", this.getStringEncoder().encode(" ")); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_NoSpace_to_Nothing() { assertEquals("", this.getStringEncoder().encode("")); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_Null_to_Nothing() { assertEquals("", this.getStringEncoder().encode(null)); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@Test public final void testGetEncoding_One_Letter_to_Nothing() { assertEquals("", this.getStringEncoder().encode("E")); }
|
@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) pObject); }
|
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) pObject); } }
|
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) pObject); } }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
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) pObject); } @Override final Object encode(final Object pObject); @Override final String encode(String name); boolean isEncodeEquals(String name1, String name2); }
|
@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(ctx); InvocationContext context = DefaultInvocationContext.create(); context.addParameter("1", false); context.addParameter("2", new Object()); context.addParameter("3", true); n.render(context); BoundSql boundSql = context.getBoundSql(); assertThat(boundSql.getSql().toString(), equalTo("select where 1=1 and id>10 ")); }
|
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 jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } }
|
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 jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } } }
|
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 jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); }
|
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 jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); }
|
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 jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0)); } } } Parser(String s); Parser(java.io.InputStream stream); Parser(java.io.InputStream stream, String encoding); Parser(Reader stream); Parser(ParserTokenManager tm); final ASTRootNode parse(); final void DML(); final void Insert(); final void Delete(); final void Update(); final void Select(); final void Replace(); final void Merge(); final void Truncate(); final void Statement(); final void JDBCParameter(); final void JDBCIterableParameter(); final void GlobalTable(); final void JoinParameter(); final void QuoteText(); final void Text(); final void Blank(); final void IfStatement(); final void ElseStatement(); final void ElseIfStatement(); final void Expression(); final void ConditionalOrExpression(); final void ConditionalAndExpression(); final void RelationalExpression(); final void UnaryExpression(); final void PrimaryExpression(); final void ExpressionParameter(); final void IntegerLiteral(); final void StringLiteral(); final void True(); final void False(); final void Null(); void ReInit(java.io.InputStream stream); void ReInit(java.io.InputStream stream, String encoding); void ReInit(Reader stream); void ReInit(ParserTokenManager tm); final Token getNextToken(); final Token getToken(int index); ParseException generateParseException(); final void enable_tracing(); final void disable_tracing(); public ParserTokenManager token_source; public Token token; public Token jj_nt; }
|
@Test public void testGetAnnotations() throws Exception { Set<Annotation> annos = new HashSet<Annotation>(); Reflection.getAnnotations(SubDao.class, annos); assertThat(annos.size(), equalTo(1)); }
|
public static Set<Annotation> getAnnotations(Class<?> clazz) { Set<Annotation> annos = new HashSet<Annotation>(); getAnnotations(clazz, annos); return annos; }
|
Reflection { public static Set<Annotation> getAnnotations(Class<?> clazz) { Set<Annotation> annos = new HashSet<Annotation>(); getAnnotations(clazz, annos); return annos; } }
|
Reflection { public static Set<Annotation> getAnnotations(Class<?> clazz) { Set<Annotation> annos = new HashSet<Annotation>(); getAnnotations(clazz, annos); return annos; } }
|
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); static T newProxy(
Class<T> interfaceType, InvocationHandler handler); static void makeAccessible(Constructor<?> ctor); static Set<Annotation> getAnnotations(Class<?> clazz); }
|
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); static T newProxy(
Class<T> interfaceType, InvocationHandler handler); static void makeAccessible(Constructor<?> ctor); static Set<Annotation> getAnnotations(Class<?> clazz); }
|
@Test public void getProjectsByProviderConfigNameTest() throws Exception { ConfigurationModel configurationModel = createConfigurationModel(); ProviderProjectEntity providerProjectEntity = new ProviderProjectEntity(name, description, href, projectOwnerEmail, 1L); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ProviderProjectRepository providerProjectRepository = Mockito.mock(ProviderProjectRepository.class); Mockito.when(configurationAccessor.getProviderConfigurationByName(Mockito.any())).thenReturn(Optional.of(configurationModel)); Mockito.when(providerProjectRepository.findByProviderConfigId(Mockito.any())).thenReturn(List.of(providerProjectEntity)); DefaultProviderDataAccessor providerDataAccessor = new DefaultProviderDataAccessor(providerProjectRepository, null, null, configurationAccessor); List<ProviderProject> providerProjectList = providerDataAccessor.getProjectsByProviderConfigName("test-providerConfigName"); assertEquals(1, providerProjectList.size()); ProviderProject providerProject = providerProjectList.get(0); testProviderProject(expectedProviderProject, providerProject); }
|
@Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName) { try { Optional<Long> optionalConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalConfigId.isPresent()) { return providerProjectRepository.findByProviderConfigId(optionalConfigId.get()) .stream() .map(this::convertToProjectModel) .collect(Collectors.toList()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName) { try { Optional<Long> optionalConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalConfigId.isPresent()) { return providerProjectRepository.findByProviderConfigId(optionalConfigId.get()) .stream() .map(this::convertToProjectModel) .collect(Collectors.toList()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName) { try { Optional<Long> optionalConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalConfigId.isPresent()) { return providerProjectRepository.findByProviderConfigId(optionalConfigId.get()) .stream() .map(this::convertToProjectModel) .collect(Collectors.toList()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName) { try { Optional<Long> optionalConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalConfigId.isPresent()) { return providerProjectRepository.findByProviderConfigId(optionalConfigId.get()) .stream() .map(this::convertToProjectModel) .collect(Collectors.toList()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) public List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName) { try { Optional<Long> optionalConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalConfigId.isPresent()) { return providerProjectRepository.findByProviderConfigId(optionalConfigId.get()) .stream() .map(this::convertToProjectModel) .collect(Collectors.toList()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); static final int MAX_DESCRIPTION_LENGTH; static final int MAX_PROJECT_NAME_LENGTH; }
|
@Test public void setTaskPropertyExceptionTest() throws Exception { DefaultProviderTaskPropertiesAccessor providerTaskPropertiesAccessor = new DefaultProviderTaskPropertiesAccessor(providerTaskPropertiesRepository); try { providerTaskPropertiesAccessor.setTaskProperty(null, "", "", ""); fail(); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
|
@Override public void setTaskProperty(Long configId, String taskName, String propertyKey, String propertyValue) throws AlertDatabaseConstraintException { if (null == configId || StringUtils.isBlank(taskName) || StringUtils.isBlank(propertyKey) || StringUtils.isBlank(propertyValue)) { throw new AlertDatabaseConstraintException("All fields are required to save a task property"); } ProviderTaskPropertiesEntity taskPropertyToSave = new ProviderTaskPropertiesEntity(configId, taskName, propertyKey, propertyValue); providerTaskPropertiesRepository.save(taskPropertyToSave); }
|
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(propertyKey) || StringUtils.isBlank(propertyValue)) { throw new AlertDatabaseConstraintException("All fields are required to save a task property"); } ProviderTaskPropertiesEntity taskPropertyToSave = new ProviderTaskPropertiesEntity(configId, taskName, propertyKey, propertyValue); providerTaskPropertiesRepository.save(taskPropertyToSave); } }
|
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(propertyKey) || StringUtils.isBlank(propertyValue)) { throw new AlertDatabaseConstraintException("All fields are required to save a task property"); } ProviderTaskPropertiesEntity taskPropertyToSave = new ProviderTaskPropertiesEntity(configId, taskName, propertyKey, propertyValue); providerTaskPropertiesRepository.save(taskPropertyToSave); } @Autowired DefaultProviderTaskPropertiesAccessor(ProviderTaskPropertiesRepository providerTaskPropertiesRepository); }
|
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(propertyKey) || StringUtils.isBlank(propertyValue)) { throw new AlertDatabaseConstraintException("All fields are required to save a task property"); } ProviderTaskPropertiesEntity taskPropertyToSave = new ProviderTaskPropertiesEntity(configId, taskName, propertyKey, propertyValue); providerTaskPropertiesRepository.save(taskPropertyToSave); } @Autowired DefaultProviderTaskPropertiesAccessor(ProviderTaskPropertiesRepository providerTaskPropertiesRepository); @Override Optional<String> getTaskProperty(String taskName, String propertyKey); @Override void setTaskProperty(Long configId, String taskName, String propertyKey, String propertyValue); }
|
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(propertyKey) || StringUtils.isBlank(propertyValue)) { throw new AlertDatabaseConstraintException("All fields are required to save a task property"); } ProviderTaskPropertiesEntity taskPropertyToSave = new ProviderTaskPropertiesEntity(configId, taskName, propertyKey, propertyValue); providerTaskPropertiesRepository.save(taskPropertyToSave); } @Autowired DefaultProviderTaskPropertiesAccessor(ProviderTaskPropertiesRepository providerTaskPropertiesRepository); @Override Optional<String> getTaskProperty(String taskName, String propertyKey); @Override void setTaskProperty(Long configId, String taskName, String propertyKey, String propertyValue); }
|
@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.setId(1L); DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name()); RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); Mockito.when(registeredDescriptorRepository.findAll()).thenReturn(List.of(registeredDescriptorEntity)); Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository); List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptors(); assertEquals(1, registeredDescriptorModelList.size()); RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelList.get(0); assertEquals(name, registeredDescriptorModel.getName()); assertEquals(descriptorType, registeredDescriptorModel.getType()); }
|
@Override public List<RegisteredDescriptorModel> getRegisteredDescriptors() throws AlertDatabaseConstraintException { List<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findAll(); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptors() throws AlertDatabaseConstraintException { List<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findAll(); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptors() throws AlertDatabaseConstraintException { List<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findAll(); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptors() throws AlertDatabaseConstraintException { List<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findAll(); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptors() throws AlertDatabaseConstraintException { List<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findAll(); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@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.setId(1L); DescriptorKey descriptorKey = createDescriptorKey("descriptorKey-test"); DescriptorKey emptyDescriptorKey = createDescriptorKey("bad-key"); DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name()); RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); Mockito.when(registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey())).thenReturn(Optional.of(registeredDescriptorEntity)); Mockito.when(registeredDescriptorRepository.findFirstByName(emptyDescriptorKey.getUniversalKey())).thenReturn(Optional.empty()); Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository); Optional<RegisteredDescriptorModel> registeredDescriptorModelOptional = descriptorAccessor.getRegisteredDescriptorByKey(descriptorKey); Optional<RegisteredDescriptorModel> registeredDescriptorModelOptionalEmpty = descriptorAccessor.getRegisteredDescriptorByKey(emptyDescriptorKey); assertTrue(registeredDescriptorModelOptional.isPresent()); RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelOptional.get(); assertFalse(registeredDescriptorModelOptionalEmpty.isPresent()); assertEquals(name, registeredDescriptorModel.getName()); assertEquals(descriptorType, registeredDescriptorModel.getType()); }
|
@Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@Test public void descriptorKeyFailureTest() throws Exception { DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(null, null, null, null); DescriptorKey descriptorKey = createDescriptorKey(""); try { descriptorAccessor.getRegisteredDescriptorByKey(descriptorKey); fail(); } catch (AlertDatabaseConstraintException e) { logger.error(e.getMessage(), e); } }
|
@Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey) throws AlertDatabaseConstraintException { if (null == descriptorKey || StringUtils.isBlank(descriptorKey.getUniversalKey())) { throw new AlertDatabaseConstraintException(String.format("DescriptorKey is not valid. %s", descriptorKey)); } Optional<RegisteredDescriptorEntity> descriptorEntity = registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey()); if (descriptorEntity.isPresent()) { return Optional.of(createRegisteredDescriptorModel(descriptorEntity.get())); } return Optional.empty(); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@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); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId); registeredDescriptorEntity.setId(1L); DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name()); descriptorTypeEntity.setId(1L); Mockito.when(descriptorTypeRepository.findFirstByType(descriptorType.name())).thenReturn(Optional.of(descriptorTypeEntity)); Mockito.when(registeredDescriptorRepository.findByTypeId(Mockito.any())).thenReturn(List.of(registeredDescriptorEntity)); Mockito.when(descriptorTypeRepository.findById(registeredDescriptorEntity.getTypeId())).thenReturn(Optional.of(descriptorTypeEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository); List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptorsByType(descriptorType); assertEquals(1, registeredDescriptorModelList.size()); RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelList.get(0); assertEquals(name, registeredDescriptorModel.getName()); assertEquals(descriptorType, registeredDescriptorModel.getType()); }
|
@Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@Test public void getRegisteredDescriptorsByTypeMissingDescriptorTypeTest() throws Exception { final String name = "name-test"; final Long typeId = 1L; final DescriptorType descriptorType = DescriptorType.CHANNEL; RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId); registeredDescriptorEntity.setId(1L); DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name()); descriptorTypeEntity.setId(1L); Mockito.when(descriptorTypeRepository.findFirstByType(descriptorType.name())).thenReturn(Optional.empty()); Mockito.when(descriptorTypeRepository.save(Mockito.any())).thenReturn(descriptorTypeEntity); Mockito.when(registeredDescriptorRepository.findByTypeId(Mockito.any())).thenReturn(List.of(registeredDescriptorEntity)); Mockito.when(descriptorTypeRepository.findById(registeredDescriptorEntity.getTypeId())).thenReturn(Optional.of(descriptorTypeEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository); List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptorsByType(descriptorType); assertEquals(1, registeredDescriptorModelList.size()); RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelList.get(0); assertEquals(name, registeredDescriptorModel.getName()); assertEquals(descriptorType, registeredDescriptorModel.getType()); }
|
@Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@Test public void descriptorTypeFailureTest() throws Exception { DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(null, null, null, null); DescriptorType descriptorType = null; try { descriptorAccessor.getRegisteredDescriptorsByType(descriptorType); fail(); } catch (AlertDatabaseConstraintException e) { logger.error(e.getMessage(), e); } }
|
@Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType) throws AlertDatabaseConstraintException { if (null == descriptorType) { throw new AlertDatabaseConstraintException("Descriptor type cannot be null"); } Long typeId = saveDescriptorTypeAndReturnId(descriptorType); Collection<RegisteredDescriptorEntity> allDescriptors = registeredDescriptorRepository.findByTypeId(typeId); List<RegisteredDescriptorModel> descriptorModels = new ArrayList<>(); for (RegisteredDescriptorEntity entity : allDescriptors) { descriptorModels.add(createRegisteredDescriptorModel(entity)); } return descriptorModels; } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@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); registeredDescriptorEntity.setId(1L); DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name()); descriptorTypeEntity.setId(2L); RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); Mockito.when(registeredDescriptorRepository.findById(descriptorId)).thenReturn(Optional.of(registeredDescriptorEntity)); Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository); Optional<RegisteredDescriptorModel> registeredDescriptorModelOptional = descriptorAccessor.getRegisteredDescriptorById(descriptorId); assertTrue(registeredDescriptorModelOptional.isPresent()); RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelOptional.get(); assertEquals(typeId, registeredDescriptorModel.getId()); assertEquals(name, registeredDescriptorModel.getName()); assertEquals(descriptorType, registeredDescriptorModel.getType()); }
|
@Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); return Optional.of(createRegisteredDescriptorModel(descriptor)); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); return Optional.of(createRegisteredDescriptorModel(descriptor)); } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); return Optional.of(createRegisteredDescriptorModel(descriptor)); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); return Optional.of(createRegisteredDescriptorModel(descriptor)); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); return Optional.of(createRegisteredDescriptorModel(descriptor)); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@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-field-key-test"; Boolean isSensitive = Boolean.TRUE; RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId); registeredDescriptorEntity.setId(1L); DescriptorKey descriptorKey = createDescriptorKey("descriptorKey-test"); ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name()); configContextEntity.setId(3L); DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(definedFieldsKey, isSensitive); RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DefinedFieldRepository definedFieldRepository = Mockito.mock(DefinedFieldRepository.class); ConfigContextRepository configContextRepository = Mockito.mock(ConfigContextRepository.class); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); Mockito.when(registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey())).thenReturn(Optional.of(registeredDescriptorEntity)); Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity)); Mockito.when(configContextRepository.findFirstByContext(invalidConfigContextEnum.name())).thenReturn(Optional.empty()); Mockito.when(configContextRepository.save(Mockito.any())).thenReturn(configContextEntity); Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, definedFieldRepository, configContextRepository, descriptorTypeRepository); List<DefinedFieldModel> definedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, configContextEnum); List<DefinedFieldModel> emptyConfigContextDefinedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, invalidConfigContextEnum); assertEquals(1, definedFieldModelList.size()); DefinedFieldModel definedFieldModel = definedFieldModelList.get(0); assertEquals(definedFieldsKey, definedFieldModel.getKey()); assertEquals(isSensitive, definedFieldModel.getSensitive()); List<ConfigContextEnum> configContextList = new ArrayList<>(definedFieldModel.getContexts()); assertEquals(configContextEnum, configContextList.get(0)); assertEquals(1, emptyConfigContextDefinedFieldModelList.size()); DefinedFieldModel emptyConfigContextDefinedFieldModel = emptyConfigContextDefinedFieldModelList.get(0); assertEquals(definedFieldsKey, emptyConfigContextDefinedFieldModel.getKey()); assertEquals(isSensitive, emptyConfigContextDefinedFieldModel.getSensitive()); List<ConfigContextEnum> configContextList2 = new ArrayList<>(emptyConfigContextDefinedFieldModel.getContexts()); assertEquals(invalidConfigContextEnum, configContextList2.get(0)); }
|
@Override public List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorByKey(descriptorKey); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorByKey(descriptorKey); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorByKey(descriptorKey); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorByKey(descriptorKey); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorByKey(descriptorKey); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@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; RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId); registeredDescriptorEntity.setId(1L); ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name()); configContextEntity.setId(3L); DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(definedFieldsKey, isSensitive); RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class); DefinedFieldRepository definedFieldRepository = Mockito.mock(DefinedFieldRepository.class); ConfigContextRepository configContextRepository = Mockito.mock(ConfigContextRepository.class); DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class); Mockito.when(registeredDescriptorRepository.findById(descriptorId)).thenReturn(Optional.of(registeredDescriptorEntity)); Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity)); Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity)); DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, definedFieldRepository, configContextRepository, descriptorTypeRepository); List<DefinedFieldModel> definedFieldModelList = descriptorAccessor.getFieldsForDescriptorById(descriptorId, configContextEnum); assertEquals(1, definedFieldModelList.size()); DefinedFieldModel definedFieldModel = definedFieldModelList.get(0); assertEquals(definedFieldsKey, definedFieldModel.getKey()); assertEquals(isSensitive, definedFieldModel.getSensitive()); List<ConfigContextEnum> configContextList = new ArrayList<>(definedFieldModel.getContexts()); assertEquals(configContextEnum, configContextList.get(0)); }
|
@Override public List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
DefaultDescriptorAccessor implements DescriptorAccessor { @Override public List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context) throws AlertDatabaseConstraintException { RegisteredDescriptorEntity descriptor = findDescriptorById(descriptorId); Long contextId = saveContextAndReturnId(context); return getFieldsForDescriptorId(descriptor.getId(), contextId, context); } @Autowired DefaultDescriptorAccessor(RegisteredDescriptorRepository registeredDescriptorRepository, DefinedFieldRepository definedFieldRepository, ConfigContextRepository configContextRepository,
DescriptorTypeRepository descriptorTypeRepository); @Override List<RegisteredDescriptorModel> getRegisteredDescriptors(); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorByKey(DescriptorKey descriptorKey); @Override List<RegisteredDescriptorModel> getRegisteredDescriptorsByType(DescriptorType descriptorType); @Override Optional<RegisteredDescriptorModel> getRegisteredDescriptorById(Long descriptorId); @Override List<DefinedFieldModel> getFieldsForDescriptor(DescriptorKey descriptorKey, ConfigContextEnum context); @Override List<DefinedFieldModel> getFieldsForDescriptorById(Long descriptorId, ConfigContextEnum context); }
|
@Test public void getUsersByProviderConfigNameOptionalEmptyTest() throws Exception { ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); Mockito.when(configurationAccessor.getProviderConfigurationByName(Mockito.any())).thenReturn(Optional.empty()); DefaultProviderDataAccessor providerDataAccessor = new DefaultProviderDataAccessor(null, null, null, configurationAccessor); List<ProviderUserModel> providerUserModelList = providerDataAccessor.getUsersByProviderConfigName("providerConfigName-test"); assertTrue(providerUserModelList.isEmpty()); }
|
@Override public List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName) { if (StringUtils.isBlank(providerConfigName)) { return List.of(); } try { Optional<Long> optionalProviderConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalProviderConfigId.isPresent()) { return getUsersByProviderConfigId(optionalProviderConfigId.get()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName) { if (StringUtils.isBlank(providerConfigName)) { return List.of(); } try { Optional<Long> optionalProviderConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalProviderConfigId.isPresent()) { return getUsersByProviderConfigId(optionalProviderConfigId.get()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName) { if (StringUtils.isBlank(providerConfigName)) { return List.of(); } try { Optional<Long> optionalProviderConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalProviderConfigId.isPresent()) { return getUsersByProviderConfigId(optionalProviderConfigId.get()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName) { if (StringUtils.isBlank(providerConfigName)) { return List.of(); } try { Optional<Long> optionalProviderConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalProviderConfigId.isPresent()) { return getUsersByProviderConfigId(optionalProviderConfigId.get()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName) { if (StringUtils.isBlank(providerConfigName)) { return List.of(); } try { Optional<Long> optionalProviderConfigId = configurationAccessor.getProviderConfigurationByName(providerConfigName) .map(ConfigurationModel::getConfigurationId); if (optionalProviderConfigId.isPresent()) { return getUsersByProviderConfigId(optionalProviderConfigId.get()); } } catch (AlertDatabaseConstraintException ignored) { } return List.of(); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); static final int MAX_DESCRIPTION_LENGTH; static final int MAX_PROJECT_NAME_LENGTH; }
|
@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 = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findAll()).thenReturn(List.of(userEntity)); createModelMocks(userRoleRelation, userRoleModel, AuthenticationType.DATABASE); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); List<UserModel> userModelList = defaultUserAccessor.getUsers(); assertEquals(1, userModelList.size()); UserModel userModel = userModelList.get(0); testUserModel(userEntity.getId(), username, emailAddress, roleName, userModel); }
|
@Override public List<UserModel> getUsers() { List<UserEntity> userList = userRepository.findAll(); return userList.stream().map(this::createModel).collect(Collectors.toList()); }
|
DefaultUserAccessor implements UserAccessor { @Override public List<UserModel> getUsers() { List<UserEntity> userList = userRepository.findAll(); return userList.stream().map(this::createModel).collect(Collectors.toList()); } }
|
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 userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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 = new UserRoleRelation(1L, 2L); UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findById(userId)).thenReturn(Optional.of(userEntity)); Mockito.when(userRepository.findById(emptyUserId)).thenReturn(Optional.empty()); createModelMocks(userRoleRelation, userRoleModel, AuthenticationType.DATABASE); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); Optional<UserModel> userModelOptional = defaultUserAccessor.getUser(userId); Optional<UserModel> userModelOptionalEmpty = defaultUserAccessor.getUser(emptyUserId); assertTrue(userModelOptional.isPresent()); assertFalse(userModelOptionalEmpty.isPresent()); UserModel userModel = userModelOptional.get(); testUserModel(userEntity.getId(), username, emailAddress, roleName, userModel); }
|
@Override public Optional<UserModel> getUser(Long userId) { return userRepository.findById(userId).map(this::createModel); }
|
DefaultUserAccessor implements UserAccessor { @Override public Optional<UserModel> getUser(Long userId) { return userRepository.findById(userId).map(this::createModel); } }
|
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, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void getUserByUsernameTest() { final String emptyUsername = ""; 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 = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findByUserName(username)).thenReturn(Optional.of(userEntity)); Mockito.when(userRepository.findByUserName(emptyUsername)).thenReturn(Optional.empty()); createModelMocks(userRoleRelation, userRoleModel, AuthenticationType.DATABASE); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); Optional<UserModel> userModelOptional = defaultUserAccessor.getUser(username); Optional<UserModel> userModelOptionalEmpty = defaultUserAccessor.getUser(emptyUsername); assertTrue(userModelOptional.isPresent()); assertFalse(userModelOptionalEmpty.isPresent()); UserModel userModel = userModelOptional.get(); testUserModel(userEntity.getId(), username, emailAddress, roleName, userModel); }
|
@Override public Optional<UserModel> getUser(Long userId) { return userRepository.findById(userId).map(this::createModel); }
|
DefaultUserAccessor implements UserAccessor { @Override public Optional<UserModel> getUser(Long userId) { return userRepository.findById(userId).map(this::createModel); } }
|
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, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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 userRoleRelation = new UserRoleRelation(1L, 2L); UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findByUserName(Mockito.any())).thenReturn(Optional.empty()); Mockito.when(authenticationTypeAccessor.getAuthenticationTypeDetails(Mockito.any())).thenReturn(Optional.of(authenticationTypeDetails)); Mockito.when(userRepository.save(Mockito.any())).thenReturn(userEntity); createModelMocks(userRoleRelation, userRoleModel, AuthenticationType.DATABASE); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); UserModel userModel = defaultUserAccessor.addUser(username, password, emailAddress); testUserModel(userEntity.getId(), username, emailAddress, roleName, userModel); }
|
@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); }
|
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); } }
|
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); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void addUserExistsTest() throws Exception { UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); Mockito.when(userRepository.findByUserName(Mockito.any())).thenReturn(Optional.of(userEntity)); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); try { defaultUserAccessor.addUser(username, password, emailAddress); fail("User with the same name that already exists in the userRepository did not throw expected AlertForbiddenOperationException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
|
@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); }
|
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); } }
|
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); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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); UserModel userModel = UserModel.existingUser(1L, username, password, emailAddress, authenticationType, Set.of(roles), true); UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L); UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(userEntity)); Mockito.when(authenticationTypeAccessor.getAuthenticationType(Mockito.any())).thenReturn(Optional.of(authenticationType)); Mockito.when(userRepository.save(Mockito.any())).thenReturn(userEntity); createModelMocks(userRoleRelation, userRoleModel, authenticationType); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); UserModel newUserModel = defaultUserAccessor.updateUser(userModel, false); Mockito.verify(roleAccessor).updateUserRoles(Mockito.eq(userEntity.getId()), Mockito.any()); testUserModel(userEntity.getId(), username, emailAddress, roleName, newUserModel); }
|
@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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void updateUserNullTest() { UserRoleModel roles = createUserRoleModel(1L, "roleName", true); UserModel userModel = UserModel.newUser(username, password, emailAddress, AuthenticationType.DATABASE, Set.of(roles), true); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); try { defaultUserAccessor.updateUser(userModel, false); fail("Null userId did not throw expected AlertForbiddenOperationException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
|
@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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void updateUserAuthenticationTypeEmptyTest() { 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); UserModel userModel = UserModel.existingUser(1L, username, password, emailAddress, authenticationType, Set.of(roles), true); Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(userEntity)); Mockito.when(authenticationTypeAccessor.getAuthenticationType(Mockito.any())).thenReturn(Optional.empty()); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); try { defaultUserAccessor.updateUser(userModel, false); fail("Null userId did not throw expected AlertForbiddenOperationException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
|
@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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void updateUserNonDatabaseAuthTest() throws Exception { final String roleName = "roleName"; AuthenticationType authenticationType = AuthenticationType.LDAP; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); UserRoleModel roles = createUserRoleModel(1L, roleName, true); UserModel userModel = UserModel.existingUser(1L, username, "", emailAddress, authenticationType, Set.of(roles), true); UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L); UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(userEntity)); Mockito.when(authenticationTypeAccessor.getAuthenticationType(Mockito.any())).thenReturn(Optional.of(authenticationType)); Mockito.when(userRepository.save(Mockito.any())).thenReturn(userEntity); createModelMocks(userRoleRelation, userRoleModel, authenticationType); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); UserModel updatedUserModel = defaultUserAccessor.updateUser(userModel, false); Mockito.verify(roleAccessor).updateUserRoles(Mockito.eq(userEntity.getId()), Mockito.any()); testUserModel(userEntity.getId(), username, emailAddress, roleName, updatedUserModel); }
|
@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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void updateUserNonDatabaseAuthInvalidTest() throws Exception { final String roleName = "roleName"; AuthenticationType authenticationType = AuthenticationType.LDAP; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); UserEntity existingUserEntity = new UserEntity("usernam-teste", "existing-password", "[email protected]", 2L); existingUserEntity.setId(1L); UserRoleModel roles = createUserRoleModel(1L, roleName, true); UserModel userModel = UserModel.existingUser(1L, username, password, emailAddress, authenticationType, Set.of(roles), true); UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L); UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true); Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(existingUserEntity)); Mockito.when(authenticationTypeAccessor.getAuthenticationType(Mockito.any())).thenReturn(Optional.of(authenticationType)); Mockito.when(userRepository.save(Mockito.any())).thenReturn(existingUserEntity); createModelMocks(userRoleRelation, userRoleModel, authenticationType); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); try { defaultUserAccessor.updateUser(userModel, false); fail("External user with did not throw expected AlertForbiddenOperationException."); } catch (AlertDatabaseConstraintException e) { assertNotNull(e); } }
|
@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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 = userRepository.findById(userId) .orElseThrow(() -> new AlertDatabaseConstraintException(String.format("No user found with id '%s'", userId))); Long existingUserId = existingUser.getId(); UserEntity savedEntity = existingUser; Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType()); if (!authenticationType.isPresent()) { throw new AlertDatabaseConstraintException("Unknown Authentication Type, user not updated."); } else if (AuthenticationType.DATABASE != authenticationType.get()) { boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName()); boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress()); boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword()); if (isUserNameInvalid || isEmailInvalid || isPasswordSet) { throw new AlertDatabaseConstraintException("An external user cannot change its credentials."); } } else { String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword()); UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType()); newEntity.setId(existingUserId); savedEntity = userRepository.save(newEntity); } roleAccessor.updateUserRoles(existingUserId, user.getRoles()); return createModel(savedEntity); } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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); ProviderProjectEntity providerProjectEntity = new ProviderProjectEntity(name, description, href, projectOwnerEmail, 1L); providerProjectEntity.setId(3L); ProviderUserEntity providerUserEntity = new ProviderUserEntity("test-email", true, 1L); providerUserEntity.setId(4L); Map<ProviderProject, Set<String>> projectToUserData = new HashMap<>(); projectToUserData.put(providerProject, Set.of("test-user-email")); final String additionalRelevantUsers = "additional-test-user-email"; ProviderProjectRepository providerProjectRepository = Mockito.mock(ProviderProjectRepository.class); ProviderUserRepository providerUserRepository = Mockito.mock(ProviderUserRepository.class); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ProviderUserProjectRelationRepository providerUserProjectRelationRepository = Mockito.mock(ProviderUserProjectRelationRepository.class); Mockito.when(providerProjectRepository.findByProviderConfigId(Mockito.any())).thenReturn(List.of(storedProviderProjectEntity)); Mockito.when(providerProjectRepository.saveAll(Mockito.any())).thenReturn(List.of(providerProjectEntity)); Mockito.when(providerUserRepository.findByProviderConfigId(Mockito.any())).thenReturn(List.of(providerUserEntity)); Mockito.when(providerUserRepository.save(Mockito.any())).thenReturn(providerUserEntity); Mockito.when(providerProjectRepository.findFirstByHref(Mockito.any())).thenReturn(Optional.of(providerProjectEntity)); Mockito.when(providerUserRepository.findByEmailAddressAndProviderConfigId(Mockito.any(), Mockito.any())).thenReturn(List.of(providerUserEntity)); DefaultProviderDataAccessor providerDataAccessor = new DefaultProviderDataAccessor(providerProjectRepository, providerUserProjectRelationRepository, providerUserRepository, configurationAccessor); providerDataAccessor.updateProjectAndUserData(1L, projectToUserData, Set.of(additionalRelevantUsers)); Mockito.verify(providerProjectRepository).deleteByHref(Mockito.any()); Mockito.verify(providerUserRepository).deleteByProviderConfigIdAndEmailAddress(Mockito.any(), Mockito.any()); Mockito.verify(providerUserProjectRelationRepository).saveAll(Mockito.any()); }
|
@Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); }
|
DefaultProviderDataAccessor implements ProviderDataAccessor { @Override public void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers) { updateProjectDB(providerConfigId, projectToUserData.keySet()); Set<String> userData = projectToUserData.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); userData.addAll(additionalRelevantUsers); updateUserDB(providerConfigId, userData); updateUserProjectRelations(providerConfigId, projectToUserData); } @Autowired DefaultProviderDataAccessor(ProviderProjectRepository providerProjectRepository, ProviderUserProjectRelationRepository providerUserProjectRelationRepository, ProviderUserRepository providerUserRepository,
ConfigurationAccessor configurationAccessor); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigName(String providerConfigName); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderProject> getProjectsByProviderConfigId(Long providerConfigId); @Override void deleteProjects(Collection<ProviderProject> providerProjects); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Set<String> getEmailAddressesForProjectHref(String projectHref); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<ProviderUserModel> getUsersByProviderConfigId(Long providerConfigId); @Override List<ProviderUserModel> getUsersByProviderConfigName(String providerConfigName); @Override void updateProjectAndUserData(Long providerConfigId, Map<ProviderProject, Set<String>> projectToUserData, Set<String> additionalRelevantUsers); static final int MAX_DESCRIPTION_LENGTH; static final int MAX_PROJECT_NAME_LENGTH; }
|
@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(userRepository.findByUserName(Mockito.eq(badUsername))).thenReturn(Optional.empty()); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); boolean assignedRoles = defaultUserAccessor.assignRoles(username, Set.of(roleId)); boolean assignedRolesFalse = defaultUserAccessor.assignRoles(badUsername, Set.of(roleId)); Mockito.verify(roleAccessor).updateUserRoles(Mockito.eq(userEntity.getId()), Mockito.any()); Mockito.verify(roleAccessor).getRoles(Mockito.any()); assertTrue(assignedRoles); assertFalse(assignedRolesFalse); }
|
@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.getRoles(roleIds)); return true; } return false; }
|
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.getRoles(roleIds)); return true; } return false; } }
|
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.getRoles(roleIds)); return true; } return false; } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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.getRoles(roleIds)); return true; } return false; } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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.getRoles(roleIds)); return true; } return false; } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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); userEntity.setId(1L); Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity)); Mockito.when(userRepository.findByUserName(Mockito.eq(badUsername))).thenReturn(Optional.empty()); Mockito.when(defaultPasswordEncoder.encode(Mockito.any())).thenReturn(newPassword); Mockito.when(userRepository.save(Mockito.any())).thenReturn(newUserEntity); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); assertTrue(defaultUserAccessor.changeUserPassword(username, newPassword)); assertFalse(defaultUserAccessor.changeUserPassword(badUsername, newPassword)); }
|
@Override public boolean changeUserPassword(String username, String newPassword) { Optional<UserEntity> entity = userRepository.findByUserName(username); if (entity.isPresent()) { return changeUserPassword(entity.get(), newPassword); } return false; }
|
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; } }
|
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 DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void changeUserEmailAddressTest() { final String badUsername = "badUsername"; final String newEmailAddress = "[email protected]"; UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); UserEntity newUserEntity = new UserEntity(username, password, newEmailAddress, 2L); userEntity.setId(1L); Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity)); Mockito.when(userRepository.findByUserName(Mockito.eq(badUsername))).thenReturn(Optional.empty()); Mockito.when(userRepository.save(Mockito.any())).thenReturn(newUserEntity); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); assertTrue(defaultUserAccessor.changeUserEmailAddress(username, newEmailAddress)); assertFalse(defaultUserAccessor.changeUserEmailAddress(badUsername, newEmailAddress)); }
|
@Override public boolean changeUserEmailAddress(String username, String emailAddress) { Optional<UserEntity> entity = userRepository.findByUserName(username); if (entity.isPresent()) { return changeUserEmailAddress(entity.get(), emailAddress); } return false; }
|
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; } }
|
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 DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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 DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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 DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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 DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); defaultUserAccessor.deleteUser(username); Mockito.verify(roleAccessor).updateUserRoles(Mockito.any(), Mockito.any()); Mockito.verify(userRepository).deleteById(Mockito.any()); }
|
@Override public void deleteUser(String userName) throws AlertForbiddenOperationException { Optional<UserEntity> optionalUser = userRepository.findByUserName(userName); if (optionalUser.isPresent()) { UserEntity user = optionalUser.get(); deleteUserEntity(user); } }
|
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); } } }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void deleteUserByIdTest() throws Exception { UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(5L); Mockito.when(userRepository.findById(Mockito.eq(userEntity.getId()))).thenReturn(Optional.of(userEntity)); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); defaultUserAccessor.deleteUser(userEntity.getId()); Mockito.verify(roleAccessor).updateUserRoles(Mockito.any(), Mockito.any()); Mockito.verify(userRepository).deleteById(Mockito.any()); }
|
@Override public void deleteUser(String userName) throws AlertForbiddenOperationException { Optional<UserEntity> optionalUser = userRepository.findByUserName(userName); if (optionalUser.isPresent()) { UserEntity user = optionalUser.get(); deleteUserEntity(user); } }
|
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); } } }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@Test public void deleteUserReservedIdTest() throws Exception { UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L); userEntity.setId(1L); Mockito.when(userRepository.findByUserName(Mockito.eq(username))).thenReturn(Optional.of(userEntity)); Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(userEntity)); DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor); try { defaultUserAccessor.deleteUser(username); fail("A forbidden userEntity id did not throw the expected AlertForbiddenOperationException"); } catch (AlertForbiddenOperationException e) { assertNotNull(e); } }
|
@Override public void deleteUser(String userName) throws AlertForbiddenOperationException { Optional<UserEntity> optionalUser = userRepository.findByUserName(userName); if (optionalUser.isPresent()) { UserEntity user = optionalUser.get(); deleteUserEntity(user); } }
|
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); } } }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
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); } } @Autowired DefaultUserAccessor(UserRepository userRepository, UserRoleRepository userRoleRepository, PasswordEncoder defaultPasswordEncoder, DefaultRoleAccessor roleAccessor,
AuthenticationTypeAccessor authenticationTypeAccessor); @Override List<UserModel> getUsers(); @Override Optional<UserModel> getUser(Long userId); @Override Optional<UserModel> getUser(String username); @Override UserModel addUser(String userName, String password, String emailAddress); @Override UserModel addUser(UserModel user, boolean passwordEncoded); @Override UserModel updateUser(UserModel user, boolean passwordEncoded); @Override boolean assignRoles(String username, Set<Long> roleIds); @Override boolean changeUserPassword(String username, String newPassword); @Override boolean changeUserEmailAddress(String username, String emailAddress); @Override void deleteUser(String userName); @Override void deleteUser(Long userId); }
|
@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 jsonObject = gson.fromJson(jsonString, JsonObject.class); Optional<String> field1Value = azureFieldsExtractor.extractField(jsonObject, FieldsTestClass.FIELD_1); assertTrue(field1Value.isPresent(), "Field 1 was not present"); assertEquals(originalCopy.getField1(), field1Value.get()); Optional<Integer> field2Value = azureFieldsExtractor.extractField(jsonObject, FieldsTestClass.FIELD_2); assertTrue(field2Value.isPresent(), "Field 2 was not present"); assertEquals(originalCopy.getField2(), field2Value.get()); Optional<FieldsTestInnerClass> field3Value = azureFieldsExtractor.extractField(jsonObject, FieldsTestClass.FIELD_3); assertTrue(field3Value.isPresent(), "Field 3 was not present"); FieldsTestInnerClass field3Object = field3Value.get(); assertEquals(originalCopy.getField3().getInnerField1(), field3Object.getInnerField1()); assertEquals(originalCopy.getField3().getInnerField2(), field3Object.getInnerField2()); }
|
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(fieldValue); } return Optional.empty(); }
|
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(fieldValue); } return Optional.empty(); } }
|
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(fieldValue); } return Optional.empty(); } AzureFieldsExtractor(Gson gson); }
|
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(fieldValue); } return Optional.empty(); } AzureFieldsExtractor(Gson gson); Optional<T> extractField(JsonObject fieldsObject, AzureFieldDefinition<T> fieldDefinition); }
|
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(fieldValue); } return Optional.empty(); } AzureFieldsExtractor(Gson gson); Optional<T> extractField(JsonObject fieldsObject, AzureFieldDefinition<T> fieldDefinition); }
|
@Test public void testServerServiceFactory() { try { JiraServerProperties properties = new JiraServerProperties("http: JiraServerServiceFactory serviceFactory = properties.createJiraServicesServerFactory(LoggerFactory.getLogger(getClass()), new Gson()); assertNotNull(serviceFactory); } catch (IssueTrackerException ex) { ex.printStackTrace(); fail(); } }
|
public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraServerRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraServerServiceFactory(intLogger, jiraHttpClient, gson); }
|
JiraServerProperties implements IssueTrackerServiceConfig { public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraServerRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraServerServiceFactory(intLogger, jiraHttpClient, gson); } }
|
JiraServerProperties implements IssueTrackerServiceConfig { public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraServerRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraServerServiceFactory(intLogger, jiraHttpClient, gson); } JiraServerProperties(String url, String password, String username, boolean pluginCheckDisabled); }
|
JiraServerProperties implements IssueTrackerServiceConfig { public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraServerRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraServerServiceFactory(intLogger, jiraHttpClient, gson); } JiraServerProperties(String url, String password, String username, boolean pluginCheckDisabled); JiraServerRestConfig createJiraServerConfig(); JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson); String getUrl(); String getPassword(); String getUsername(); boolean isPluginCheckDisabled(); }
|
JiraServerProperties implements IssueTrackerServiceConfig { public JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraServerRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraServerServiceFactory(intLogger, jiraHttpClient, gson); } JiraServerProperties(String url, String password, String username, boolean pluginCheckDisabled); JiraServerRestConfig createJiraServerConfig(); JiraServerServiceFactory createJiraServicesServerFactory(Logger logger, Gson gson); String getUrl(); String getPassword(); String getUsername(); boolean isPluginCheckDisabled(); }
|
@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 issueMetaDataService = Mockito.mock(IssueMetaDataService.class); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); String resolveTransitionString = "Resolve"; String projectName = "ProjectName"; String issueTypeString = "IssueType"; String issueCreatorString = "IssueCreator"; IssueConfig issueConfig = new IssueConfig(); issueConfig.setCommentOnIssues(true); issueConfig.setResolveTransition(resolveTransitionString); issueConfig.setProjectName(projectName); issueConfig.setIssueType(issueTypeString); issueConfig.setIssueCreator(issueCreatorString); IssueTypeResponseModel issue = Mockito.mock(IssueTypeResponseModel.class); Mockito.when(issue.getName()).thenReturn(issueTypeString); List<IssueTypeResponseModel> issueResponses = new ArrayList<>(1); issueResponses.add(issue); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueResponses); UserDetailsResponseModel user = Mockito.mock(UserDetailsResponseModel.class); Mockito.when(user.getName()).thenReturn(issueCreatorString); Mockito.when(userSearchService.findUserByUsername(Mockito.anyString())).thenReturn(Optional.of(user)); ProjectComponent projectComponent = Mockito.mock(ProjectComponent.class); Mockito.when(projectComponent.getName()).thenReturn(projectName); List<ProjectComponent> projectComponents = new ArrayList<>(1); projectComponents.add(projectComponent); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(projectComponents); try { IssueTrackerContext context = new IssueTrackerContext(null, issueConfig); jiraIssueConfigValidator.createValidIssueConfig(context); Assertions.assertEquals(resolveTransitionString, issueConfig.getResolveTransition().orElse("")); Assertions.assertEquals(projectName, issueConfig.getProjectName()); Assertions.assertEquals(issueCreatorString, issueConfig.getIssueCreator()); Assertions.assertEquals(issueTypeString, issueConfig.getIssueType()); } catch (AlertFieldException e) { fail(); } }
|
@Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { return projectService.getProjectsByName(jiraProjectName); }
|
JiraServerIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { return projectService.getProjectsByName(jiraProjectName); } }
|
JiraServerIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { return projectService.getProjectsByName(jiraProjectName); } JiraServerIssueConfigValidator(ProjectService projectService, UserSearchService userSearchService, IssueTypeService issueTypeService, IssueMetaDataService issueMetaDataService); }
|
JiraServerIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { return projectService.getProjectsByName(jiraProjectName); } JiraServerIssueConfigValidator(ProjectService projectService, UserSearchService userSearchService, IssueTypeService issueTypeService, IssueMetaDataService issueMetaDataService); @Override String getProjectFieldKey(); @Override String getIssueTypeFieldKey(); @Override String getIssueCreatorFieldKey(); @Override String getAddCommentsFieldKey(); @Override String getResolveTransitionFieldKey(); @Override String getOpenTransitionFieldKey(); @Override Collection<ProjectComponent> getProjectsByName(String jiraProjectName); @Override boolean isUserValid(String issueCreator); }
|
JiraServerIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { return projectService.getProjectsByName(jiraProjectName); } JiraServerIssueConfigValidator(ProjectService projectService, UserSearchService userSearchService, IssueTypeService issueTypeService, IssueMetaDataService issueMetaDataService); @Override String getProjectFieldKey(); @Override String getIssueTypeFieldKey(); @Override String getIssueCreatorFieldKey(); @Override String getAddCommentsFieldKey(); @Override String getResolveTransitionFieldKey(); @Override String getOpenTransitionFieldKey(); @Override Collection<ProjectComponent> getProjectsByName(String jiraProjectName); @Override boolean isUserValid(String issueCreator); }
|
@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 missing.")); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }
|
@Test public void getSettingsKeysTest() { final String key = "key1"; final String key2 = "key2"; final String value1 = "value1"; final String value2 = "value2"; SettingsKeyEntity settingsKeyEntity1 = new SettingsKeyEntity(key, value1); SettingsKeyEntity settingsKeyEntity2 = new SettingsKeyEntity(key2, value2); settingsKeyEntity1.setId(1L); settingsKeyEntity2.setId(2L); SettingsKeyRepository settingsKeyRepository = new MockSettingsKeyRepository(); settingsKeyRepository.save(settingsKeyEntity1); settingsKeyRepository.save(settingsKeyEntity2); DefaultSettingsKeyAccessor settingsKeyAccessor = new DefaultSettingsKeyAccessor(settingsKeyRepository); List<SettingsKeyModel> settingsKeyModelList = settingsKeyAccessor.getSettingsKeys(); assertEquals(2, settingsKeyModelList.size()); SettingsKeyModel settingsKeyModel1 = settingsKeyModelList.get(0); SettingsKeyModel settingsKeyModel2 = settingsKeyModelList.get(1); assertEquals(key, settingsKeyModel1.getKey()); assertEquals(value1, settingsKeyModel1.getValue()); assertEquals(key2, settingsKeyModel2.getKey()); assertEquals(value2, settingsKeyModel2.getValue()); }
|
@Override public List<SettingsKeyModel> getSettingsKeys() { return settingsKeyRepository.findAll() .stream() .map(this::convertToSettingsKeyModel) .collect(Collectors.toList()); }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public List<SettingsKeyModel> getSettingsKeys() { return settingsKeyRepository.findAll() .stream() .map(this::convertToSettingsKeyModel) .collect(Collectors.toList()); } }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public List<SettingsKeyModel> getSettingsKeys() { return settingsKeyRepository.findAll() .stream() .map(this::convertToSettingsKeyModel) .collect(Collectors.toList()); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public List<SettingsKeyModel> getSettingsKeys() { return settingsKeyRepository.findAll() .stream() .map(this::convertToSettingsKeyModel) .collect(Collectors.toList()); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); @Override List<SettingsKeyModel> getSettingsKeys(); @Override Optional<SettingsKeyModel> getSettingsKeyByKey(String key); @Override SettingsKeyModel saveSettingsKey(String key, String value); @Override void deleteSettingsKeyByKey(String key); @Override void deleteSettingsKeyById(Long id); }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public List<SettingsKeyModel> getSettingsKeys() { return settingsKeyRepository.findAll() .stream() .map(this::convertToSettingsKeyModel) .collect(Collectors.toList()); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); @Override List<SettingsKeyModel> getSettingsKeys(); @Override Optional<SettingsKeyModel> getSettingsKeyByKey(String key); @Override SettingsKeyModel saveSettingsKey(String key, String value); @Override void deleteSettingsKeyByKey(String key); @Override void deleteSettingsKeyById(Long id); }
|
@Test public void testRequestsNull() throws Exception { JiraServerRequestDelegator service = new JiraServerRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = null; try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Requests missing.")); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }
|
@Test public void testRequestsEmpty() throws Exception { JiraServerRequestDelegator service = new JiraServerRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Requests missing.")); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }
|
@Test public void testAppMissing() throws Exception { JiraServerChannel jiraServerChannel = new JiraServerChannel(gson, new JiraServerChannelKey(), null, null, null); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); IssueSearchProperties searchProperties = createSearchProperties(); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); requests.add(IssueCreationRequest.of(searchProperties, content, alertIssueOrigin)); requests.add(IssueCommentRequest.of(searchProperties, content, alertIssueOrigin)); requests.add(IssueResolutionRequest.of(searchProperties, content, alertIssueOrigin)); Mockito.when(pluginManagerService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(false); try { jiraServerChannel.sendRequests(createContext(), requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Please configure the Jira Server plugin")); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }
|
@Test public void testCreateIssue() throws Exception { Mockito.when(pluginManagerService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(true); List<ProjectComponent> projectComponents = new ArrayList<>(); projectComponents.add(new ProjectComponent(null, "1", "project", "project", null, null, null, null)); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(projectComponents); List<IssueTypeResponseModel> issueTypes = new ArrayList<>(); issueTypes.add(new TestIssueTypeResponseModel()); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueTypes); Optional<UserDetailsResponseModel> userDetails = Optional.of(new TestIssueCreator()); Mockito.when(userSearchService.findUserByUsername(Mockito.anyString())).thenReturn(userDetails); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); List<IssueSearchIssueComponent> issues = new ArrayList<>(); IssueSearchResponseModel searchResponseModel = new IssueSearchResponseModel("", issues); Mockito.when(issueSearchService.queryForIssues(Mockito.anyString())).thenReturn(searchResponseModel); IssueResponseModel issue = createIssueResponse(); Mockito.when(issueService.createIssue(Mockito.any(IssueCreationRequestModel.class))).thenReturn(issue); JiraServerRequestDelegator service = new JiraServerRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); IssueSearchProperties searchProperties = Mockito.mock(JiraIssueSearchProperties.class); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); requests.add(IssueCreationRequest.of(searchProperties, content, alertIssueOrigin)); IssueTrackerResponse response = service.sendRequests(requests); assertNotNull(response); assertNotNull(response.getStatusMessage()); boolean anyIssuesMatchKey = response.getUpdatedIssues() .stream() .map(IssueTrackerIssueResponseModel::getIssueKey) .anyMatch("project-1"::equals); assertTrue(anyIssuesMatchKey, "No issues matched the expected key"); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }
|
@Test public void testResolveIssue() throws Exception { Mockito.when(pluginManagerService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(true); List<ProjectComponent> projectComponents = new ArrayList<>(); projectComponents.add(new ProjectComponent(null, "1", "project", "project", null, null, null, null)); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(projectComponents); List<IssueTypeResponseModel> issueTypes = new ArrayList<>(); issueTypes.add(new TestIssueTypeResponseModel()); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueTypes); Optional<UserDetailsResponseModel> userDetails = Optional.of(new TestIssueCreator()); Mockito.when(userSearchService.findUserByUsername(Mockito.anyString())).thenReturn(userDetails); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); List<IssueSearchIssueComponent> issues = new ArrayList<>(); issues.add(new TestIssueSearchIssueComponent()); IssueSearchResponseModel searchResponseModel = new IssueSearchResponseModel("", issues); Mockito.when(issueSearchService.queryForIssues(Mockito.anyString())).thenReturn(searchResponseModel); Mockito.when(issueService.getIssue(Mockito.anyString())).thenReturn(createIssueResponse()); StatusDetailsComponent statusDetailsComponent = new TestNewStatusDetailsComponent(); Mockito.when(issueService.getStatus(Mockito.anyString())).thenReturn(statusDetailsComponent); TransitionsResponseModel transitionsResponseModel = new TestTransitionResponsesModel(); Mockito.when(issueService.getTransitions(Mockito.anyString())).thenReturn(transitionsResponseModel); JiraServerRequestDelegator service = new JiraServerRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); IssueSearchProperties searchProperties = Mockito.mock(JiraIssueSearchProperties.class); requests.add(IssueCommentRequest.of(searchProperties, content, alertIssueOrigin)); requests.add(IssueResolutionRequest.of(searchProperties, content, alertIssueOrigin)); IssueTrackerResponse response = service.sendRequests(requests); assertNotNull(response); assertNotNull(response.getStatusMessage()); boolean anyIssuesMatchKey = response.getUpdatedIssues() .stream() .map(IssueTrackerIssueResponseModel::getIssueKey) .anyMatch("project-1"::equals); assertTrue(anyIssuesMatchKey, "No issues matched the expected key"); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
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 IssueTrackerException("Requests missing. Require at least one request."); } JiraServerProperties jiraProperties = (JiraServerProperties) context.getIssueTrackerConfig(); JiraServerServiceFactory jiraServerServiceFactory = jiraProperties.createJiraServicesServerFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraServerServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraServerServiceFactory.createProjectService(); UserSearchService userSearchService = jiraServerServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraServerServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraServerServiceFactory.createIssueMetadataService(); JiraServerIssueConfigValidator jiraIssueConfigValidator = new JiraServerIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraServerServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraServerServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraServerServiceFactory.createIssueSearchService(); JiraContentValidator jiraContentValidator = new JiraContentValidator(); JiraServerTransitionHandler jiraTransitionHandler = new JiraServerTransitionHandler(issueService); JiraServerIssuePropertyHandler jiraIssuePropertyHandler = new JiraServerIssuePropertyHandler(issueSearchService, issuePropertyService); JiraServerIssueHandler jiraIssueHandler = new JiraServerIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, jiraContentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraServerRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); static final String ERROR_MESSAGE_PLUGIN_CONFIG; }
|
@Test public void testContextNull() throws Exception { JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(gson, null); List<IssueTrackerRequest> requests = new ArrayList<>(); try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Context missing.")); } }
|
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
@Test public void testRequestsNull() throws Exception { JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = null; try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Requests missing.")); } }
|
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
@Test public void testRequestsEmpty() throws Exception { JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Requests missing.")); } }
|
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
@Test public void testAppMissing() throws Exception { JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); IssueSearchProperties searchProperties = createSearchProperties(); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); requests.add(IssueCreationRequest.of(searchProperties, content, alertIssueOrigin)); requests.add(IssueCommentRequest.of(searchProperties, content, alertIssueOrigin)); requests.add(IssueResolutionRequest.of(searchProperties, content, alertIssueOrigin)); Mockito.when(jiraAppService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(false); try { service.sendRequests(requests); fail(); } catch (IssueTrackerException ex) { assertTrue(ex.getMessage().contains("Please configure the Jira Cloud plugin")); } }
|
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
@Test public void testCreateIssue() throws Exception { Mockito.when(jiraAppService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(true); List<ProjectComponent> pageComponents = new ArrayList<>(); pageComponents.add(new ProjectComponent(null, "1", "project", "project", null, null, null, null)); PageOfProjectsResponseModel pageOfProjects = new PageOfProjectsResponseModel(pageComponents); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(pageOfProjects); List<IssueTypeResponseModel> issueTypes = new ArrayList<>(); issueTypes.add(new TestIssueTypeResponseModel()); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueTypes); List<UserDetailsResponseModel> userDetails = new ArrayList<>(); userDetails.add(new TestIssueCreator()); Mockito.when(userSearchService.findUser(Mockito.anyString())).thenReturn(userDetails); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); IssueSearchResponseModel searchResponseModel = new IssueSearchResponseModel(); List<IssueResponseModel> issues = new ArrayList<>(); searchResponseModel.setIssues(issues); Mockito.when(issueSearchService.queryForIssues(Mockito.anyString())).thenReturn(searchResponseModel); IssueResponseModel issue = createIssueResponse(); Mockito.when(issueService.createIssue(Mockito.any(IssueCreationRequestModel.class))).thenReturn(issue); JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); IssueSearchProperties searchProperties = Mockito.mock(JiraIssueSearchProperties.class); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); requests.add(IssueCreationRequest.of(searchProperties, content, alertIssueOrigin)); IssueTrackerResponse response = service.sendRequests(requests); assertNotNull(response); assertNotNull(response.getStatusMessage()); boolean anyIssuesMatchKey = response.getUpdatedIssues() .stream() .map(IssueTrackerIssueResponseModel::getIssueKey) .anyMatch("project-1"::equals); assertTrue(anyIssuesMatchKey, "No issues matched the expected key"); }
|
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
@Test public void getSettingsByKeyTest() { final String key = "key1"; final String value1 = "value1"; SettingsKeyEntity settingsKeyEntity = new SettingsKeyEntity(key, value1); settingsKeyEntity.setId(1L); SettingsKeyRepository settingsKeyRepository = new MockSettingsKeyRepository(); settingsKeyRepository.save(settingsKeyEntity); DefaultSettingsKeyAccessor settingsKeyAccessor = new DefaultSettingsKeyAccessor(settingsKeyRepository); Optional<SettingsKeyModel> settingsKeyModelOptional = settingsKeyAccessor.getSettingsKeyByKey("key1"); Optional<SettingsKeyModel> settingsKeyModelOptionalNull = settingsKeyAccessor.getSettingsKeyByKey("-1"); assertTrue(settingsKeyModelOptional.isPresent()); assertFalse(settingsKeyModelOptionalNull.isPresent()); SettingsKeyModel settingsKeyModel = settingsKeyModelOptional.get(); assertEquals(key, settingsKeyModel.getKey()); assertEquals(value1, settingsKeyModel.getValue()); }
|
@Override public Optional<SettingsKeyModel> getSettingsKeyByKey(String key) { return settingsKeyRepository.findByKey(key).map(this::convertToSettingsKeyModel); }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public Optional<SettingsKeyModel> getSettingsKeyByKey(String key) { return settingsKeyRepository.findByKey(key).map(this::convertToSettingsKeyModel); } }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public Optional<SettingsKeyModel> getSettingsKeyByKey(String key) { return settingsKeyRepository.findByKey(key).map(this::convertToSettingsKeyModel); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public Optional<SettingsKeyModel> getSettingsKeyByKey(String key) { return settingsKeyRepository.findByKey(key).map(this::convertToSettingsKeyModel); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); @Override List<SettingsKeyModel> getSettingsKeys(); @Override Optional<SettingsKeyModel> getSettingsKeyByKey(String key); @Override SettingsKeyModel saveSettingsKey(String key, String value); @Override void deleteSettingsKeyByKey(String key); @Override void deleteSettingsKeyById(Long id); }
|
DefaultSettingsKeyAccessor implements SettingsKeyAccessor { @Override public Optional<SettingsKeyModel> getSettingsKeyByKey(String key) { return settingsKeyRepository.findByKey(key).map(this::convertToSettingsKeyModel); } DefaultSettingsKeyAccessor(SettingsKeyRepository settingsKeyRepository); @Override List<SettingsKeyModel> getSettingsKeys(); @Override Optional<SettingsKeyModel> getSettingsKeyByKey(String key); @Override SettingsKeyModel saveSettingsKey(String key, String value); @Override void deleteSettingsKeyByKey(String key); @Override void deleteSettingsKeyById(Long id); }
|
@Test public void testResolveIssue() throws Exception { Mockito.when(jiraAppService.isAppInstalled(Mockito.eq(JiraConstants.JIRA_APP_KEY))).thenReturn(true); List<ProjectComponent> pageComponents = new ArrayList<>(); pageComponents.add(new ProjectComponent(null, "1", "project", "project", null, null, null, null)); PageOfProjectsResponseModel pageOfProjects = new PageOfProjectsResponseModel(pageComponents); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(pageOfProjects); List<IssueTypeResponseModel> issueTypes = new ArrayList<>(); issueTypes.add(new TestIssueTypeResponseModel()); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueTypes); List<UserDetailsResponseModel> userDetails = new ArrayList<>(); userDetails.add(new TestIssueCreator()); Mockito.when(userSearchService.findUser(Mockito.anyString())).thenReturn(userDetails); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); IssueSearchResponseModel searchResponseModel = new IssueSearchResponseModel(); List<IssueResponseModel> issues = new ArrayList<>(); issues.add(createIssueResponse()); searchResponseModel.setIssues(issues); Mockito.when(issueSearchService.queryForIssues(Mockito.anyString())).thenReturn(searchResponseModel); StatusDetailsComponent statusDetailsComponent = new TestNewStatusDetailsComponent(); Mockito.when(issueService.getStatus(Mockito.anyString())).thenReturn(statusDetailsComponent); TransitionsResponseModel transitionsResponseModel = new TestTransitionResponsesModel(); Mockito.when(issueService.getTransitions(Mockito.anyString())).thenReturn(transitionsResponseModel); JiraCloudRequestDelegator service = new JiraCloudRequestDelegator(gson, createContext()); List<IssueTrackerRequest> requests = new ArrayList<>(); IssueContentModel content = createContentModel(); IssueSearchProperties searchProperties = Mockito.mock(JiraIssueSearchProperties.class); AlertIssueOrigin alertIssueOrigin = new AlertIssueOrigin(null, null); requests.add(IssueCommentRequest.of(searchProperties, content, alertIssueOrigin)); requests.add(IssueResolutionRequest.of(searchProperties, content, alertIssueOrigin)); IssueTrackerResponse response = service.sendRequests(requests); assertNotNull(response); assertNotNull(response.getStatusMessage()); boolean anyIssuesMatchKey = response.getUpdatedIssues() .stream() .map(IssueTrackerIssueResponseModel::getIssueKey) .anyMatch("project-1"::equals); assertTrue(anyIssuesMatchKey, "No issues matched the expected key"); }
|
public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
JiraCloudRequestDelegator { public IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests) throws IntegrationException { if (null == context) { throw new IssueTrackerException("Context missing. Cannot determine Jira Cloud instance."); } if (null == requests || requests.isEmpty()) { throw new IssueTrackerException("Requests missing. Requires at least one request."); } JiraCloudProperties jiraProperties = (JiraCloudProperties) context.getIssueTrackerConfig(); JiraCloudServiceFactory jiraCloudServiceFactory = jiraProperties.createJiraServicesCloudFactory(logger, gson); if (!jiraProperties.isPluginCheckDisabled()) { checkIfAlertPluginIsInstalled(jiraCloudServiceFactory.createPluginManagerService()); } ProjectService projectService = jiraCloudServiceFactory.createProjectService(); UserSearchService userSearchService = jiraCloudServiceFactory.createUserSearchService(); IssueTypeService issueTypeService = jiraCloudServiceFactory.createIssueTypeService(); IssueMetaDataService issueMetaDataService = jiraCloudServiceFactory.createIssueMetadataService(); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); IssueConfig validIssueConfig = jiraIssueConfigValidator.createValidIssueConfig(context); IssueService issueService = jiraCloudServiceFactory.createIssueService(); IssuePropertyService issuePropertyService = jiraCloudServiceFactory.createIssuePropertyService(); IssueSearchService issueSearchService = jiraCloudServiceFactory.createIssueSearchService(); JiraContentValidator contentValidator = new JiraContentValidator(); JiraCloudTransitionHandler jiraTransitionHandler = new JiraCloudTransitionHandler(issueService); JiraCloudIssuePropertyHandler jiraIssuePropertyHandler = new JiraCloudIssuePropertyHandler(issueSearchService, issuePropertyService); JiraCloudIssueHandler jiraIssueHandler = new JiraCloudIssueHandler(issueService, jiraProperties, gson, jiraTransitionHandler, jiraIssuePropertyHandler, contentValidator); return jiraIssueHandler.createOrUpdateIssues(validIssueConfig, requests); } JiraCloudRequestDelegator(Gson gson, IssueTrackerContext context); IssueTrackerResponse sendRequests(List<IssueTrackerRequest> requests); }
|
@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 issueMetaDataService = Mockito.mock(IssueMetaDataService.class); Mockito.when(issueMetaDataService.doesProjectContainIssueType(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE); JiraCloudIssueConfigValidator jiraIssueConfigValidator = new JiraCloudIssueConfigValidator(projectService, userSearchService, issueTypeService, issueMetaDataService); String resolveTransitionString = "Resolve"; String projectName = "ProjectName"; String issueTypeString = "IssueType"; String issueCreatorString = "IssueCreator"; IssueConfig issueConfig = new IssueConfig(); issueConfig.setCommentOnIssues(true); issueConfig.setResolveTransition(resolveTransitionString); issueConfig.setProjectName(projectName); issueConfig.setIssueType(issueTypeString); issueConfig.setIssueCreator(issueCreatorString); IssueTypeResponseModel issue = Mockito.mock(IssueTypeResponseModel.class); Mockito.when(issue.getName()).thenReturn(issueTypeString); List<IssueTypeResponseModel> issueResponses = new ArrayList<>(1); issueResponses.add(issue); Mockito.when(issueTypeService.getAllIssueTypes()).thenReturn(issueResponses); UserDetailsResponseModel user = Mockito.mock(UserDetailsResponseModel.class); Mockito.when(user.getEmailAddress()).thenReturn(issueCreatorString); List<UserDetailsResponseModel> userResponses = new ArrayList<>(1); userResponses.add(user); Mockito.when(userSearchService.findUser(Mockito.anyString())).thenReturn(userResponses); ProjectComponent projectComponent = Mockito.mock(ProjectComponent.class); Mockito.when(projectComponent.getName()).thenReturn(projectName); PageOfProjectsResponseModel projectResponse = Mockito.mock(PageOfProjectsResponseModel.class); List<ProjectComponent> projectComponents = new ArrayList<>(1); projectComponents.add(projectComponent); Mockito.when(projectResponse.getProjects()).thenReturn(projectComponents); Mockito.when(projectService.getProjectsByName(Mockito.anyString())).thenReturn(projectResponse); try { IssueTrackerContext context = new IssueTrackerContext(null, issueConfig); jiraIssueConfigValidator.createValidIssueConfig(context); Assertions.assertEquals(resolveTransitionString, issueConfig.getResolveTransition().orElse("")); Assertions.assertEquals(projectName, issueConfig.getProjectName()); Assertions.assertEquals(issueCreatorString, issueConfig.getIssueCreator()); Assertions.assertEquals(issueTypeString, issueConfig.getIssueType()); } catch (AlertFieldException e) { fail(); } }
|
@Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { PageOfProjectsResponseModel projectsResponseModel = projectService.getProjectsByName(jiraProjectName); return projectsResponseModel.getProjects(); }
|
JiraCloudIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { PageOfProjectsResponseModel projectsResponseModel = projectService.getProjectsByName(jiraProjectName); return projectsResponseModel.getProjects(); } }
|
JiraCloudIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { PageOfProjectsResponseModel projectsResponseModel = projectService.getProjectsByName(jiraProjectName); return projectsResponseModel.getProjects(); } JiraCloudIssueConfigValidator(ProjectService projectService, UserSearchService userSearchService, IssueTypeService issueTypeService, IssueMetaDataService issueMetaDataService); }
|
JiraCloudIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { PageOfProjectsResponseModel projectsResponseModel = projectService.getProjectsByName(jiraProjectName); return projectsResponseModel.getProjects(); } JiraCloudIssueConfigValidator(ProjectService projectService, UserSearchService userSearchService, IssueTypeService issueTypeService, IssueMetaDataService issueMetaDataService); @Override String getProjectFieldKey(); @Override String getIssueTypeFieldKey(); @Override String getIssueCreatorFieldKey(); @Override String getAddCommentsFieldKey(); @Override String getResolveTransitionFieldKey(); @Override String getOpenTransitionFieldKey(); @Override Collection<ProjectComponent> getProjectsByName(String jiraProjectName); @Override boolean isUserValid(String issueCreator); }
|
JiraCloudIssueConfigValidator extends JiraIssueConfigValidator { @Override public Collection<ProjectComponent> getProjectsByName(String jiraProjectName) throws IntegrationException { PageOfProjectsResponseModel projectsResponseModel = projectService.getProjectsByName(jiraProjectName); return projectsResponseModel.getProjects(); } JiraCloudIssueConfigValidator(ProjectService projectService, UserSearchService userSearchService, IssueTypeService issueTypeService, IssueMetaDataService issueMetaDataService); @Override String getProjectFieldKey(); @Override String getIssueTypeFieldKey(); @Override String getIssueCreatorFieldKey(); @Override String getAddCommentsFieldKey(); @Override String getResolveTransitionFieldKey(); @Override String getOpenTransitionFieldKey(); @Override Collection<ProjectComponent> getProjectsByName(String jiraProjectName); @Override boolean isUserValid(String issueCreator); }
|
@Test public void testServerServiceFactory() { try { JiraCloudProperties properties = new JiraCloudProperties("http: JiraCloudServiceFactory serviceFactory = properties.createJiraServicesCloudFactory(LoggerFactory.getLogger(getClass()), new Gson()); assertNotNull(serviceFactory); } catch (IssueTrackerException ex) { ex.printStackTrace(); fail(); } }
|
public JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraCloudRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraCloudServiceFactory(intLogger, jiraHttpClient, gson); }
|
JiraCloudProperties implements IssueTrackerServiceConfig { public JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraCloudRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraCloudServiceFactory(intLogger, jiraHttpClient, gson); } }
|
JiraCloudProperties implements IssueTrackerServiceConfig { public JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraCloudRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraCloudServiceFactory(intLogger, jiraHttpClient, gson); } JiraCloudProperties(String url, String accessToken, String username, boolean pluginCheckDisabled); }
|
JiraCloudProperties implements IssueTrackerServiceConfig { public JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraCloudRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraCloudServiceFactory(intLogger, jiraHttpClient, gson); } JiraCloudProperties(String url, String accessToken, String username, boolean pluginCheckDisabled); JiraCloudRestConfig createJiraServerConfig(); JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson); String getUrl(); String getAccessToken(); String getUsername(); boolean isPluginCheckDisabled(); }
|
JiraCloudProperties implements IssueTrackerServiceConfig { public JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson) throws IssueTrackerException { JiraCloudRestConfig jiraServerConfig = createJiraServerConfig(); Slf4jIntLogger intLogger = new Slf4jIntLogger(logger); JiraHttpClient jiraHttpClient = jiraServerConfig.createJiraHttpClient(intLogger); return new JiraCloudServiceFactory(intLogger, jiraHttpClient, gson); } JiraCloudProperties(String url, String accessToken, String username, boolean pluginCheckDisabled); JiraCloudRestConfig createJiraServerConfig(); JiraCloudServiceFactory createJiraServicesCloudFactory(Logger logger, Gson gson); String getUrl(); String getAccessToken(); String getUsername(); boolean isPluginCheckDisabled(); }
|
@Test public void testResponseBodyBuilder() { ResponseBodyBuilder responseBodyBuilder = new ResponseBodyBuilder("55L", "Message"); responseBodyBuilder.put("Key1", "Value"); responseBodyBuilder.put("Key2", 22); responseBodyBuilder.put("Key3", false); assertEquals("{\"id\":\"55L\",\"message\":\"Message\",\"Key1\":\"Value\",\"Key2\":22,\"Key3\":false}", responseBodyBuilder.build()); }
|
public ResponseBodyBuilder() { map = new JsonObject(); }
|
ResponseBodyBuilder { public ResponseBodyBuilder() { map = new JsonObject(); } }
|
ResponseBodyBuilder { public ResponseBodyBuilder() { map = new JsonObject(); } ResponseBodyBuilder(); ResponseBodyBuilder(String id, String message); ResponseBodyBuilder(String message); }
|
ResponseBodyBuilder { public ResponseBodyBuilder() { map = new JsonObject(); } ResponseBodyBuilder(); ResponseBodyBuilder(String id, String message); ResponseBodyBuilder(String message); ResponseBodyBuilder put(String key, Boolean value); ResponseBodyBuilder put(String key, Number value); ResponseBodyBuilder put(String key, String value); ResponseBodyBuilder putErrors(List<AlertFieldStatus> errors); String build(); @Override String toString(); }
|
ResponseBodyBuilder { public ResponseBodyBuilder() { map = new JsonObject(); } ResponseBodyBuilder(); ResponseBodyBuilder(String id, String message); ResponseBodyBuilder(String message); ResponseBodyBuilder put(String key, Boolean value); ResponseBodyBuilder put(String key, Number value); ResponseBodyBuilder put(String key, String value); ResponseBodyBuilder putErrors(List<AlertFieldStatus> errors); String build(); @Override String toString(); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.