@Override public PdcClassification getPreDefinedClassification(String nodeId, String instanceId) { if (isDefined(nodeId)) { return mock.getPreDefinedClassification(nodeId, instanceId); } else { return mock.getPreDefinedClassification(instanceId); } }
private void initializeBehaviour() { when(mock.findAPreDefinedClassification(anyString(), anyString())) .thenReturn(PdcClassification.NONE_CLASSIFICATION); when(mock.getPreDefinedClassification(anyString())) .thenReturn(PdcClassification.NONE_CLASSIFICATION); when(mock.getPreDefinedClassification(anyString(), anyString())) .thenReturn(PdcClassification.NONE_CLASSIFICATION); when(mock.savePreDefinedClassification(any(PdcClassification.class))) .thenAnswer( new Answer<PdcClassification>() { @Override public PdcClassification answer(InvocationOnMock invocation) throws Throwable { PdcClassificationService mock = (PdcClassificationService) invocation.getMock(); PdcClassification classification = (PdcClassification) invocation.getArguments()[0]; if (classification.getId() != null && classification.isEmpty() && findAPreDefinedClassification( classification.getNodeId(), classification.getComponentInstanceId()) != PdcClassification.NONE_CLASSIFICATION) { when(mock.findAPreDefinedClassification( classification.getNodeId(), classification.getComponentInstanceId())) .thenReturn(PdcClassification.NONE_CLASSIFICATION); return PdcClassification.NONE_CLASSIFICATION; } ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); Set<ConstraintViolation<PdcClassification>> violations = validatorFactory.getValidator().validate(classification); if (!violations.isEmpty()) { throw new ConstraintViolationException("Error", null); } ReflectionTestUtils.setField(classification, "id", id++); when(mock.findAPreDefinedClassification( classification.getNodeId(), classification.getComponentInstanceId())) .thenReturn(classification); if (classification.isPredefinedForANode()) { when(mock.getPreDefinedClassification( classification.getNodeId(), classification.getComponentInstanceId())) .thenReturn(classification); } else { when(mock.getPreDefinedClassification(classification.getComponentInstanceId())) .thenReturn(classification); } return classification; } }); }
@Override public PdcClassification findAPreDefinedClassification(String nodeId, String instanceId) { return mock.findAPreDefinedClassification(nodeId, instanceId); }
@Override public PdcClassification getPreDefinedClassification(String instanceId) { return mock.getPreDefinedClassification(instanceId); }
@Override public PdcClassification savePreDefinedClassification(PdcClassification classification) { return mock.savePreDefinedClassification(classification); }
@Override public void classifyContent( SilverpeasContent content, PdcClassification withClassification, boolean alertSubscribers) throws PdcRuntimeException { mock.classifyContent(content, withClassification, alertSubscribers); }
@Override public void axisDeleted(String axisId) { mock.axisDeleted(axisId); }
@Override public void axisValuesDeleted(List<PdcAxisValue> deletedValues) { mock.axisValuesDeleted(deletedValues); }
@Override public void classifyContent(SilverpeasContent content, PdcClassification withClassification) throws PdcRuntimeException { mock.classifyContent(content, withClassification); }
@Override public void deletePreDefinedClassification(String nodeId, String instanceId) { mock.deletePreDefinedClassification(nodeId, instanceId); }