### Question:
AgentLogParser { LogExtracts tryParse(String message) { for (Extractor extractor : Extractor.values()) { Matcher matcher = extractor.newMatcher(message); if (matcher.matches()) { return extract(extractor, matcher); } } return null; }    }### Answer:
@Test public void parsesJavaAgentSuccessMessages() { String message = "Access to http: "id=amadmin,ou=user,dc=openam,dc=forgerock,dc=org"; AgentLogParser.LogExtracts logExtracts = logParser.tryParse(message); assertThat(logExtracts.getResourceUrl()).isEqualTo("http: assertThat(logExtracts.getSubjectId()).isEqualTo("id=amadmin,ou=user,dc=openam,dc=forgerock,dc=org"); assertThat(logExtracts.getStatusCode()).isEqualTo("allowed"); assertThat(logExtracts.getStatus()).isEqualTo(ResponseStatus.SUCCESSFUL); }
@Test public void parsesWebAgentSuccessMessages() { String message = "User amadmin was allowed access tohttp: AgentLogParser.LogExtracts logExtracts = logParser.tryParse(message); assertThat(logExtracts.getResourceUrl()).isEqualTo("http: assertThat(logExtracts.getSubjectId()).isEqualTo("amadmin"); assertThat(logExtracts.getStatusCode()).isEqualTo("allowed"); assertThat(logExtracts.getStatus()).isEqualTo(ResponseStatus.SUCCESSFUL); }
@Test public void parsesJavaAgentFailureMessages() { String message = "Access tohttp: "id=amadmin,ou=user,dc=openam,dc=forgerock,dc=org"; AgentLogParser.LogExtracts logExtracts = logParser.tryParse(message); assertThat(logExtracts.getResourceUrl()).isEqualTo("http: assertThat(logExtracts.getSubjectId()).isEqualTo("id=amadmin,ou=user,dc=openam,dc=forgerock,dc=org"); assertThat(logExtracts.getStatusCode()).isEqualTo("denied"); assertThat(logExtracts.getStatus()).isEqualTo(ResponseStatus.FAILED); }
@Test public void parsesWebAgentFailureMessages() { String message = "User amadmin was denied access to http: AgentLogParser.LogExtracts logExtracts = logParser.tryParse(message); assertThat(logExtracts.getResourceUrl()).isEqualTo("http: assertThat(logExtracts.getSubjectId()).isEqualTo("amadmin"); assertThat(logExtracts.getStatusCode()).isEqualTo("denied"); assertThat(logExtracts.getStatus()).isEqualTo(ResponseStatus.FAILED); }
@Test public void unknownMessage() { String message = "Fred is not going to be given access to the fridge"; AgentLogParser.LogExtracts logExtracts = logParser.tryParse(message); assertThat(logExtracts).isNull(); }