-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change for bean providers functionality: If bean is not found provide…
…r throws RuntimeException
- Loading branch information
Showing
21 changed files
with
498 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rc/test/java/com/technologicgroup/boost/audit/providers/BeanProviderAuditFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.technologicgroup.boost.audit.providers; | ||
|
||
import com.technologicgroup.boost.audit.AuditItem; | ||
import com.technologicgroup.boost.audit.AuditItemAccessor; | ||
import com.technologicgroup.boost.common.ContextHolder; | ||
import com.technologicgroup.boost.mock.*; | ||
import org.apache.ignite.lang.IgniteCallable; | ||
import org.apache.ignite.lang.IgniteRunnable; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BeanProviderAuditFactoryTest { | ||
private BeanProviderAuditFactory factory; | ||
|
||
@SuppressWarnings("unused") | ||
@InjectMocks | ||
private ContextHolder contextHolder; | ||
|
||
@Mock | ||
private ApplicationContext context; | ||
|
||
@Mock | ||
private AuditItemAccessor auditItemAccessor; | ||
|
||
@Before | ||
public void setUp() { | ||
when(context.getBean(AuditItemAccessor.class)).thenReturn(auditItemAccessor); | ||
factory = new BeanProviderAuditFactory(); | ||
} | ||
|
||
@Test | ||
public void testGetRunnable() { | ||
IgniteRunnable runnable = factory.getRunnable(TestRunnableBean.class); | ||
|
||
Assert.assertNotNull(runnable); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
@Test | ||
public void testGetJob() { | ||
IgniteCallable<Integer> callable = factory.getJob(TestClusterJob.class); | ||
|
||
Assert.assertNotNull(callable); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
@Test | ||
public void testGetTask() { | ||
IgniteCallable<Integer> callable = factory.getTask(TestClusterTask.class, UUID.randomUUID().toString()); | ||
|
||
Assert.assertNotNull(callable); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
@Test | ||
public void testGetTask_trackable_OK() { | ||
String trackingId = UUID.randomUUID().toString(); | ||
IgniteCallable<Integer> callable = factory.getTask(TestTrackableClusterTask.class, new TestTrackableArg(10, trackingId)); | ||
|
||
Assert.assertNotNull(callable); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...it/src/test/java/com/technologicgroup/boost/audit/providers/BeanProviderAuditJobTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.technologicgroup.boost.audit.providers; | ||
|
||
import com.technologicgroup.boost.audit.AuditItem; | ||
import com.technologicgroup.boost.audit.AuditItemAccessor; | ||
import com.technologicgroup.boost.common.ContextHolder; | ||
import com.technologicgroup.boost.mock.TestClusterJob; | ||
import com.technologicgroup.boost.mock.TestClusterTask; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BeanProviderAuditJobTest { | ||
|
||
@SuppressWarnings("unused") | ||
@InjectMocks | ||
private ContextHolder contextHolder; | ||
|
||
@Mock | ||
private ApplicationContext context; | ||
|
||
@Mock | ||
private AuditItemAccessor auditItemAccessor; | ||
|
||
private BeanProviderAuditJob<Integer, ?> provider; | ||
|
||
@Before | ||
public void setUp() { | ||
provider = new BeanProviderAuditJob<>(TestClusterJob.class); | ||
} | ||
|
||
@Test | ||
public void testCall_OK() { | ||
when(context.getBean(TestClusterJob.class)).thenReturn(new TestClusterJob(10)); | ||
when(context.getBean(AuditItemAccessor.class)).thenReturn(auditItemAccessor); | ||
|
||
Integer result = provider.call(); | ||
|
||
verify(context, times(1)).getBean(TestClusterJob.class); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
Assert.assertEquals(10, result.longValue()); | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void testCall_bean_notFound() { | ||
when(context.getBean(TestClusterJob.class)).thenReturn(null); | ||
provider.call(); | ||
} | ||
|
||
@Test | ||
public void testCall_exception_tracked() { | ||
when(context.getBean(TestClusterJob.class)).thenReturn(new TestClusterJob(TestClusterJob.EXCEPTION_CODE)); | ||
when(context.getBean(AuditItemAccessor.class)).thenReturn(auditItemAccessor); | ||
|
||
try { | ||
provider.call(); | ||
Assert.fail(); | ||
} catch (Exception e) { | ||
Assert.assertEquals(TestClusterTask.MESSAGE, e.getMessage()); | ||
} | ||
|
||
verify(context, times(1)).getBean(TestClusterJob.class); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...c/test/java/com/technologicgroup/boost/audit/providers/BeanProviderAuditRunnableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.technologicgroup.boost.audit.providers; | ||
|
||
import com.technologicgroup.boost.audit.AuditItem; | ||
import com.technologicgroup.boost.audit.AuditItemAccessor; | ||
import com.technologicgroup.boost.common.ContextHolder; | ||
import com.technologicgroup.boost.mock.TestFailRunnableBean; | ||
import com.technologicgroup.boost.mock.TestRunnableBean; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BeanProviderAuditRunnableTest { | ||
|
||
@SuppressWarnings("unused") | ||
@InjectMocks | ||
private ContextHolder contextHolder; | ||
|
||
@Mock | ||
private ApplicationContext context; | ||
|
||
@Mock | ||
private AuditItemAccessor auditItemAccessor; | ||
|
||
private BeanProviderAuditRunnable<?> provider; | ||
|
||
@Before | ||
public void setUp() { | ||
provider = new BeanProviderAuditRunnable<>(TestRunnableBean.class); | ||
} | ||
|
||
@Test | ||
public void testCall_run_OK() { | ||
when(context.getBean(TestRunnableBean.class)).thenReturn(new TestRunnableBean()); | ||
when(context.getBean(AuditItemAccessor.class)).thenReturn(auditItemAccessor); | ||
|
||
provider.run(); | ||
|
||
verify(context, times(1)).getBean(TestRunnableBean.class); | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void testRun_bean_notFound() { | ||
when(context.getBean(TestRunnableBean.class)).thenReturn(null); | ||
provider.run(); | ||
} | ||
|
||
@Test | ||
public void testRun_exception_tracked() { | ||
provider = new BeanProviderAuditRunnable<>(TestFailRunnableBean.class); | ||
when(context.getBean(TestFailRunnableBean.class)).thenReturn(new TestFailRunnableBean()); | ||
when(context.getBean(AuditItemAccessor.class)).thenReturn(auditItemAccessor); | ||
|
||
try { | ||
provider.run(); | ||
Assert.fail(); | ||
} catch (Exception e) { | ||
Assert.assertEquals(TestFailRunnableBean.MESSAGE, e.getMessage()); | ||
} | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...t/src/test/java/com/technologicgroup/boost/audit/providers/BeanProviderAuditTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.technologicgroup.boost.audit.providers; | ||
|
||
import com.technologicgroup.boost.audit.AuditItem; | ||
import com.technologicgroup.boost.audit.AuditItemAccessor; | ||
import com.technologicgroup.boost.common.ContextHolder; | ||
import com.technologicgroup.boost.mock.TestClusterTask; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BeanProviderAuditTaskTest { | ||
|
||
@SuppressWarnings("unused") | ||
@InjectMocks | ||
private ContextHolder contextHolder; | ||
|
||
@Mock | ||
private ApplicationContext context; | ||
|
||
@Mock | ||
private AuditItemAccessor auditItemAccessor; | ||
|
||
private BeanProviderAuditTask<String, Integer, TestClusterTask> provider; | ||
|
||
@Test | ||
public void testRun_OK() { | ||
provider = new BeanProviderAuditTask<>(TestClusterTask.class, "10"); | ||
when(context.getBean(TestClusterTask.class)).thenReturn(new TestClusterTask()); | ||
Integer result = provider.call(); | ||
|
||
verify(context, times(1)).getBean(TestClusterTask.class); | ||
Assert.assertEquals(10, result.longValue()); | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void testCall_run_bean_notFound() { | ||
provider = new BeanProviderAuditTask<>(TestClusterTask.class, "10"); | ||
when(context.getBean(TestClusterTask.class)).thenReturn(null); | ||
provider.call(); | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void testCall_run_exception() { | ||
provider = new BeanProviderAuditTask<>(TestClusterTask.class, null); | ||
when(context.getBean(TestClusterTask.class)).thenReturn(new TestClusterTask()); | ||
provider.call(); | ||
} | ||
|
||
@Test | ||
public void testCall_run_exception_tracked() { | ||
provider = new BeanProviderAuditTask<>(TestClusterTask.class, null); | ||
when(context.getBean(TestClusterTask.class)).thenReturn(new TestClusterTask()); | ||
when(context.getBean(AuditItemAccessor.class)).thenReturn(auditItemAccessor); | ||
|
||
try { | ||
provider.call(); | ||
Assert.fail(); | ||
} catch (Exception e) { | ||
Assert.assertEquals(TestClusterTask.MESSAGE, e.getMessage()); | ||
} | ||
verify(auditItemAccessor, times(1)).put(any(String.class), any(AuditItem.class)); | ||
} | ||
|
||
} |
Oops, something went wrong.