@Test public void testReservedWordsNamingPolicy() { PolicyContext context = new PolicyContext(); context.setProperty("NAME", TEST_STRING_SHOULD_FAIL); ExecutionResult exResult = policy.execute(context); Assert.assertFalse(exResult.getStatus()); context.setProperty("NAME", TEST_STRING_SHOULD_PASS); exResult = policy.execute(context); Assert.assertTrue(exResult.getStatus()); }
@Override public ExecutionResult execute(PolicyContext context) { ExecutionResult result = new ExecutionResult(context, true, ""); String name = context.getProperty("NAME", String.class); String found = ""; for (int i=0; i<RESERVED_WORDS.length; i++) { if (name.toLowerCase().indexOf(RESERVED_WORDS[i].toLowerCase()) > -1) { result.setStatus(false); found = RESERVED_WORDS[i]; } } if (!result.getStatus()) result.setMessage("Name must not contain the words \"" + found + "\""); return result; }
ReservedWordsNamingPolicy implements Policy { @Override public ExecutionResult execute(PolicyContext context) { ExecutionResult result = new ExecutionResult(context, true, ""); String name = context.getProperty("NAME", String.class); String found = ""; for (int i=0; i<RESERVED_WORDS.length; i++) { if (name.toLowerCase().indexOf(RESERVED_WORDS[i].toLowerCase()) > -1) { result.setStatus(false); found = RESERVED_WORDS[i]; } } if (!result.getStatus()) result.setMessage("Name must not contain the words \"" + found + "\""); return result; } }
ReservedWordsNamingPolicy implements Policy { @Override public ExecutionResult execute(PolicyContext context) { ExecutionResult result = new ExecutionResult(context, true, ""); String name = context.getProperty("NAME", String.class); String found = ""; for (int i=0; i<RESERVED_WORDS.length; i++) { if (name.toLowerCase().indexOf(RESERVED_WORDS[i].toLowerCase()) > -1) { result.setStatus(false); found = RESERVED_WORDS[i]; } } if (!result.getStatus()) result.setMessage("Name must not contain the words \"" + found + "\""); return result; }  }
ReservedWordsNamingPolicy implements Policy { @Override public ExecutionResult execute(PolicyContext context) { ExecutionResult result = new ExecutionResult(context, true, ""); String name = context.getProperty("NAME", String.class); String found = ""; for (int i=0; i<RESERVED_WORDS.length; i++) { if (name.toLowerCase().indexOf(RESERVED_WORDS[i].toLowerCase()) > -1) { result.setStatus(false); found = RESERVED_WORDS[i]; } } if (!result.getStatus()) result.setMessage("Name must not contain the words \"" + found + "\""); return result; }  @Override ExecutionResult execute(PolicyContext context); }
ReservedWordsNamingPolicy implements Policy { @Override public ExecutionResult execute(PolicyContext context) { ExecutionResult result = new ExecutionResult(context, true, ""); String name = context.getProperty("NAME", String.class); String found = ""; for (int i=0; i<RESERVED_WORDS.length; i++) { if (name.toLowerCase().indexOf(RESERVED_WORDS[i].toLowerCase()) > -1) { result.setStatus(false); found = RESERVED_WORDS[i]; } } if (!result.getStatus()) result.setMessage("Name must not contain the words \"" + found + "\""); return result; }  @Override ExecutionResult execute(PolicyContext context);  }