ServiceIdConverter { ServiceIdConversionError encodeServiceId(MsgImpl msgImpl, int hasMsgKey) { if (msgImpl.hasServiceName()) { return encodeServiceIdFromName(msgImpl.serviceName(), msgImpl.rsslMsg(), hasMsgKey); } else if (msgImpl.hasServiceId()) { return validateServiceId(msgImpl.serviceId()); } return NONE; } ServiceIdConverter(OmmIProviderDirectoryStore ommIProviderDirectoryStore);   }
@Test public void shouldSetServiceIdAndReturnErrorCodeNone() { when(mockDirectoryStore.serviceId(SERVICE_NAME)).thenReturn(SERVICE_ID); when(msg.hasServiceName()).thenReturn(true); when(msg.serviceName()).thenReturn(SERVICE_NAME); ServiceIdConverter.ServiceIdConversionError result = converter.encodeServiceId(msg, HAS_MSG_KEY); assertEquals(ServiceIdConverter.ServiceIdConversionError.NONE, result); verify(mockMsgKey).serviceId(SERVICE_ID.value()); verify(mockMsgKey).applyHasServiceId(); verify(mockRsslMessage).flags(HAS_MSG_KEY); }
@Test public void shouldReturnErrorCodeNoneWhenServiceNameAndIdAreMissing() { ServiceIdConverter.ServiceIdConversionError result = converter.encodeServiceId(msg, HAS_MSG_KEY); assertEquals(ServiceIdConverter.ServiceIdConversionError.NONE, result); verifyZeroInteractions(mockMsgKey); }
@Test public void shouldReturnErrorWhenServiceIdIsMissingForName() { when(msg.hasServiceName()).thenReturn(true); when(msg.serviceName()).thenReturn(SERVICE_NAME); ServiceIdConverter.ServiceIdConversionError result = converter.encodeServiceId(msg, HAS_MSG_KEY); assertEquals(ServiceIdConverter.ServiceIdConversionError.ID_IS_MISSING_FOR_NAME, result); verifyZeroInteractions(mockMsgKey); }
@Test public void shouldReturnErrorWhenServiceIdIsInvalidForName() { when(mockDirectoryStore.serviceId(SERVICE_NAME)) .thenReturn(INVALID_SERVICE_ID); when(msg.hasServiceName()).thenReturn(true); when(msg.serviceName()).thenReturn(SERVICE_NAME); ServiceIdConverter.ServiceIdConversionError result = converter.encodeServiceId(msg, HAS_MSG_KEY); assertEquals(ServiceIdConverter.ServiceIdConversionError.ID_IS_INVALID_FOR_NAME, result); verifyZeroInteractions(mockMsgKey); }
@Test public void shouldReturnErrorWhenServiceIdHasNoNameInDirectory() { when(msg.hasServiceId()).thenReturn(true); when(msg.serviceId()).thenReturn(SERVICE_ID.value()); ServiceIdConverter.ServiceIdConversionError result = converter.encodeServiceId(msg, HAS_MSG_KEY); assertEquals(ServiceIdConverter.ServiceIdConversionError.NAME_IS_MISSING_FOR_ID, result); verifyZeroInteractions(mockMsgKey); }
@Test public void shouldReturnErrorWhenServiceIdIsInvalid() { when(msg.hasServiceId()).thenReturn(true); when(msg.serviceId()).thenReturn(INVALID_SERVICE_ID.value()); ServiceIdConverter.ServiceIdConversionError result = converter.encodeServiceId(msg, HAS_MSG_KEY); assertEquals(ServiceIdConverter.ServiceIdConversionError.USER_DEFINED_ID_INVALID, result); verifyZeroInteractions(mockMsgKey); }