/** * Test the registering of the method sensor type to method occurring not for the first * time. */ @Test public void registerSensorTypeWithMethodSecondTime() { long platformId = 1; long methodId = 20; long methodSensorId = 50; long methodIdentToSensorTypeId = 100L; when(methodIdentToSensorTypeDao.findId(eq(methodId), eq(methodSensorId), anyBoolean())).thenReturn(methodIdentToSensorTypeId); registrationService.addSensorTypeToMethod(platformId, methodSensorId, methodId); verify(methodIdentToSensorTypeDao, times(1)).findId(methodId, methodSensorId, true); verify(platformIdentCache, times(1)).markDirty(platformId); verifyZeroInteractions(methodIdentDao); verifyZeroInteractions(methodSensorTypeIdentDao); } }
printOutDefinedIPs(definedIPs);
/** * Test that the registration of the {@link MethodSensorTypeIdent} will be correct if * properties are provided. */ @SuppressWarnings("unchecked") @Test public void registerExistingMethodSensorTypeWithSettings() { final long methodSensorId = 30; long platformId = 1; final String fqcName = "class"; String regEx = "myRegEx"; String regExTemplate = "myRegExTemplate"; Map<String, Object> settings = MapUtils.putAll(new HashMap<String, Object>(), new String[][] { { "regEx", regEx }, { "regExTemplate", regExTemplate } }); when(methodSensorTypeIdentDao.findIdByClassNameAndPlatformId(fqcName, platformId)).thenReturn(Collections.singletonList(methodSensorId)); long registeredId = registrationService.registerMethodSensorTypeIdent(platformId, fqcName, settings); assertThat(registeredId, is(equalTo(methodSensorId))); verify(methodSensorTypeIdentDao, times(1)).updateParameters(methodSensorId, settings); } }
/** * Tests that an exception will be thrown if the database returns two or more platform * idents after findByExample search. * * @throws BusinessException */ @Test(expectedExceptions = { BusinessException.class }) public void noRegistrationTwoAgents() throws BusinessException { List<String> definedIps = new ArrayList<>(); definedIps.add("ip"); String agentName = "agentName"; String version = "version"; List<PlatformIdent> dbResponseList = new ArrayList<>(); dbResponseList.add(new PlatformIdent()); dbResponseList.add(new PlatformIdent()); when(platformIdentDao.findByNameAndIps(agentName, definedIps)).thenReturn(dbResponseList); registrationService.registerPlatformIdent(definedIps, agentName, version); }
/** * Confirm that {@link BusinessException} is thrown if platform ident can not be located. */ @Test(expectedExceptions = { BusinessException.class }) public void unregisterNotExistingPlatformIdent() throws BusinessException { long platformId = 10; when(agentStatusDataProvider.registerDisconnected(platformId)).thenReturn(false); registrationService.unregisterPlatformIdent(platformId); } }
/** * Tests registration of the existing {@link MethodIdent}. */ @Test public void registerExistnigMethodIdent() { final long methodId = 20; long platformId = 1; String packageName = "package"; String className = "class"; String methodName = "method"; List<String> parameterTypes = new ArrayList<>(); parameterTypes.add("parameter"); String returnType = "returnType"; int modifiers = 2; when(methodIdentDao.findIdForPlatformIdAndExample(eq(platformId), (MethodIdent) anyObject(), anyBoolean())).thenReturn(Collections.singletonList(methodId)); long registeredId = registrationService.registerMethodIdent(platformId, packageName, className, methodName, parameterTypes, returnType, modifiers); assertThat(registeredId, equalTo(methodId)); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<MethodIdent> argument = ArgumentCaptor.forClass(MethodIdent.class); verify(methodIdentDao, times(1)).findIdForPlatformIdAndExample(eq(platformId), argument.capture(), eq(true)); verify(platformIdentCache, times(1)).markDirty(platformId); assertThat(argument.getValue().getPackageName(), is(equalTo(packageName))); assertThat(argument.getValue().getClassName(), is(equalTo(className))); assertThat(argument.getValue().getMethodName(), is(equalTo(methodName))); assertThat(argument.getValue().getParameters(), is(equalTo(parameterTypes))); assertThat(argument.getValue().getReturnType(), is(equalTo(returnType))); assertThat(argument.getValue().getModifiers(), is(equalTo(modifiers))); } }
@Test public void successfully() { registrationService.updateMethodIdentTimestamp(10L, "package", "class"); verify(methodIdentDao).updateTimestamps(10L, "package", "class"); verify(platformIdentCache).markDirty(10L); }
/** * Test the registration of the JMX sensor type ident. */ @Test public void registerJmxSensorTypeIdent() { final long jmxSensorId = 50; long platformId = 1; String fqcName = "class"; when(jmxSensorTypeIdentDao.findIdByExample(eq(platformId), (JmxSensorTypeIdent) anyObject())).thenReturn(Collections.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { JmxSensorTypeIdent jmxSensorTypeIdent = (JmxSensorTypeIdent) invocation.getArguments()[0]; jmxSensorTypeIdent.setId(Long.valueOf(jmxSensorId)); return null; } }).when(jmxSensorTypeIdentDao).saveOrUpdate((JmxSensorTypeIdent) anyObject()); long registeredId = registrationService.registerJmxSensorTypeIdent(platformId, fqcName); assertThat(registeredId, is(equalTo(jmxSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<JmxSensorTypeIdent> jmxSensorArgument = ArgumentCaptor.forClass(JmxSensorTypeIdent.class); verify(jmxSensorTypeIdentDao, times(1)).saveOrUpdate(jmxSensorArgument.capture()); assertThat(jmxSensorArgument.getValue().getFullyQualifiedClassName(), is(equalTo(fqcName))); assertThat(jmxSensorArgument.getValue().getPlatformIdent().getId(), is(equalTo(platformId))); verify(platformIdentCache, times(1)).markDirty(platformId); } }
/** * Test the registration of the platform sensor type. */ @Test public void registerPlatformSensorType() { final long platformSensorId = 20; long platformId = 1; final String fqcName = "class"; when(platformSensorTypeIdentDao.findIdByClassNameAndPlatformId(fqcName, platformId)).thenReturn(Collections.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { PlatformSensorTypeIdent platformSensorTypeIdent = (PlatformSensorTypeIdent) invocation.getArguments()[0]; platformSensorTypeIdent.setId(Long.valueOf(platformSensorId)); platformSensorTypeIdent.setFullyQualifiedClassName(fqcName); return null; } }).when(platformSensorTypeIdentDao).saveOrUpdate((PlatformSensorTypeIdent) anyObject()); long registeredId = registrationService.registerPlatformSensorTypeIdent(platformId, fqcName); assertThat(registeredId, is(equalTo(platformSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<PlatformSensorTypeIdent> platformSensorArgument = ArgumentCaptor.forClass(PlatformSensorTypeIdent.class); verify(platformSensorTypeIdentDao, times(1)).saveOrUpdate(platformSensorArgument.capture()); assertThat(platformSensorArgument.getValue().getFullyQualifiedClassName(), is(equalTo(fqcName))); assertThat(platformSensorArgument.getValue().getPlatformIdent().getId(), is(equalTo(platformId))); verify(platformIdentCache, times(1)).markDirty(platformId); } }
long registeredId = registrationService.registerJmxSensorDefinitionDataIdent(platformId, mBeanObjectName, mBeanAttributeName, mBeanAttributeDescription, mBeanAttributeType, isIs, isReadable, isWritable); assertThat(registeredId, is(equalTo(jmxSensorId)));
long registeredId = registrationService.registerPlatformIdent(definedIps, agentName, version); assertThat(registeredId, is(equalTo(platformId)));
/** * Test unregistration of platform ident. */ @Test public void unregisterPlatformIdent() throws BusinessException { long platformId = 10; when(agentStatusDataProvider.registerDisconnected(platformId)).thenReturn(true); registrationService.unregisterPlatformIdent(platformId); verify(agentStatusDataProvider, times(1)).registerDisconnected(platformId); }
long registeredId = registrationService.registerMethodIdent(platformId, packageName, className, methodName, parameterTypes, returnType, modifiers);
long registeredId = registrationService.registerPlatformIdent(definedIps, agentName, version); assertThat(registeredId, is(equalTo(platformId)));
/** * Test that the registration of the {@link MethodSensorTypeIdent} will be correct if * properties are provided. */ @SuppressWarnings("unchecked") @Test public void registerMethodSensorTypeWithSettings() { final long methodSensorId = 30; long platformId = 1; final String fqcName = "class"; String regEx = "myRegEx"; String regExTemplate = "myRegExTemplate"; Map<String, Object> settings = MapUtils.putAll(new HashMap<String, Object>(), new String[][] { { "regEx", regEx }, { "regExTemplate", regExTemplate } }); when(methodSensorTypeIdentDao.findIdByClassNameAndPlatformId(fqcName, platformId)).thenReturn(Collections.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { MethodSensorTypeIdent methodSensorIdent = (MethodSensorTypeIdent) invocation.getArguments()[0]; methodSensorIdent.setId(Long.valueOf(methodSensorId)); methodSensorIdent.setFullyQualifiedClassName(fqcName); return null; } }).when(methodSensorTypeIdentDao).saveOrUpdate((MethodSensorTypeIdent) anyObject()); long registeredId = registrationService.registerMethodSensorTypeIdent(platformId, fqcName, settings); assertThat(registeredId, is(equalTo(methodSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<MethodSensorTypeIdent> methodSensorArgument = ArgumentCaptor.forClass(MethodSensorTypeIdent.class); verify(methodSensorTypeIdentDao, times(1)).saveOrUpdate(methodSensorArgument.capture()); assertThat(methodSensorArgument.getValue().getSettings(), is(settings)); }
/** * Test the registering of the method sensor type to method occurring for the first time. */ @Test public void registerSensorTypeWithMethodFirstTime() { long platformId = 1; long methodId = 20; long methodSensorId = 50; when(methodIdentToSensorTypeDao.findId(eq(methodId), eq(methodSensorId), anyBoolean())).thenReturn(null); registrationService.addSensorTypeToMethod(platformId, methodSensorId, methodId); ArgumentCaptor<MethodIdentToSensorType> argument = ArgumentCaptor.forClass(MethodIdentToSensorType.class); verify(methodIdentToSensorTypeDao, times(1)).saveOrUpdate(argument.capture()); verify(methodIdentToSensorTypeDao, times(1)).findId(methodId, methodSensorId, true); verify(platformIdentCache, times(1)).markDirty(platformId); verifyZeroInteractions(methodIdentDao); verifyZeroInteractions(methodSensorTypeIdentDao); assertThat(argument.getValue().getMethodIdent().getId(), is(equalTo(methodId))); assertThat(argument.getValue().getMethodSensorTypeIdent().getId(), is(equalTo(methodSensorId))); }
long registeredId = registrationService.registerPlatformIdent(definedIps, agentName, version); assertThat(registeredId, equalTo(platformId));
/** * Test the registration of the method sensor type. */ @Test public void registerMethodSensorType() { final long methodSensorId = 30; long platformId = 1; final String fqcName = "class"; when(methodSensorTypeIdentDao.findIdByClassNameAndPlatformId(fqcName, platformId)).thenReturn(Collections.<Long> emptyList()); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { MethodSensorTypeIdent methodSensorIdent = (MethodSensorTypeIdent) invocation.getArguments()[0]; methodSensorIdent.setId(Long.valueOf(methodSensorId)); methodSensorIdent.setFullyQualifiedClassName(fqcName); return null; } }).when(methodSensorTypeIdentDao).saveOrUpdate((MethodSensorTypeIdent) anyObject()); long registeredId = registrationService.registerMethodSensorTypeIdent(platformId, fqcName, Collections.<String, Object> emptyMap()); assertThat(registeredId, is(equalTo(methodSensorId))); verify(platformIdentCache, times(1)).markDirty(platformId); ArgumentCaptor<MethodSensorTypeIdent> methodSensorArgument = ArgumentCaptor.forClass(MethodSensorTypeIdent.class); verify(methodSensorTypeIdentDao, times(1)).saveOrUpdate(methodSensorArgument.capture()); assertThat(methodSensorArgument.getValue().getFullyQualifiedClassName(), is(equalTo(fqcName))); assertThat(methodSensorArgument.getValue().getPlatformIdent().getId(), is(equalTo(platformId))); verify(platformIdentCache, times(1)).markDirty(platformId); }
when(platformIdentDao.findByName(agentName)).thenReturn(findByExampleList); long registeredId = registrationService.registerPlatformIdent(definedIps, agentName, version); assertThat(registeredId, equalTo(platformId));