This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from dovie/develop
Improved test coverage.
- Loading branch information
Showing
3 changed files
with
205 additions
and
10 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
104 changes: 104 additions & 0 deletions
104
symphony-client/src/test/java/org/symphonyoss/symphony/clients/SignalsClientTest.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,104 @@ | ||
package org.symphonyoss.symphony.clients; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Spy; | ||
import org.powermock.api.mockito.internal.mockcreation.RuntimeExceptionProxy; | ||
import org.symphonyoss.client.SymphonyClient; | ||
import org.symphonyoss.client.exceptions.SignalsException; | ||
import org.symphonyoss.symphony.agent.api.SignalsApi; | ||
import org.symphonyoss.symphony.agent.invoker.ApiException; | ||
import org.symphonyoss.symphony.agent.model.BaseSignal; | ||
import org.symphonyoss.symphony.agent.model.Signal; | ||
import org.symphonyoss.symphony.agent.model.SuccessResponse; | ||
import org.symphonyoss.symphony.clients.impl.SignalsClientImpl; | ||
import org.symphonyoss.symphony.clients.model.SymSignal; | ||
import org.symphonyoss.symphony.clients.model.SymSignalTest; | ||
import org.symphonyoss.util.TestFactory; | ||
|
||
public class SignalsClientTest { | ||
|
||
SignalsClient signalsClient; | ||
SymphonyClient testClient; | ||
|
||
@Spy | ||
SignalsApi api; | ||
@Spy | ||
SignalsClientImpl spySignalsClient; | ||
|
||
@Before | ||
public void setUp() { | ||
testClient = TestFactory.getSymClient(); | ||
signalsClient = testClient.getSignalsClient(); | ||
spySignalsClient = spy(new SignalsClientImpl(testClient.getSymAuth(), testClient.getConfig())); | ||
api = mock(SignalsApi.class); | ||
when(spySignalsClient.createSignalsApi()).thenReturn(api); | ||
} | ||
|
||
@Test | ||
public void getClientTest() throws Exception { | ||
assertTrue("get DEFAULT client", SignalsFactory.getClient(testClient) instanceof SignalsClientImpl); | ||
} | ||
|
||
@Test | ||
public void createSignalTest() throws Exception { | ||
SymSignal signal = new SymSignal(); | ||
signal.setName(SymSignalTest.DUMMY_NAME); | ||
signal.setQuery(SymSignalTest.DUMMY_QUERY); | ||
|
||
Signal apiSignal = SymSignal.toSignal(signal); | ||
when(api.v1SignalsCreatePost(anyString(), any(BaseSignal.class), anyString())).thenReturn(apiSignal); | ||
SymSignal result = spySignalsClient.createSignal(signal); | ||
assertEquals(SymSignalTest.DUMMY_NAME, result.getName()); | ||
assertEquals(SymSignalTest.DUMMY_QUERY, result.getQuery()); | ||
} | ||
|
||
@Test | ||
public void createSignalWithError() throws Exception { | ||
when(api.v1SignalsCreatePost(anyString(), any(BaseSignal.class), anyString())).thenThrow(new ApiException()); | ||
try { | ||
spySignalsClient.createSignal(new SymSignal()); | ||
} catch (Throwable sig) { | ||
// NOTE we will get a runtimeExceptionProxy due to how this is mocked | ||
assertTrue(sig instanceof RuntimeExceptionProxy); | ||
// This is the part we would expect in real life. | ||
assertTrue(sig.getCause() instanceof SignalsException); | ||
assertTrue(sig.getCause().getCause() instanceof ApiException); | ||
} | ||
} | ||
|
||
@Test | ||
public void updateSignalTest() throws Exception { | ||
SymSignal signal = new SymSignal(); | ||
signal.setName(SymSignalTest.DUMMY_NAME); | ||
signal.setQuery(SymSignalTest.DUMMY_QUERY); | ||
signal.setId(SymSignalTest.DUMMY_ID); | ||
when(api.v1SignalsIdUpdatePost(anyString(), anyString(), any(BaseSignal.class), anyString())).thenReturn(SymSignal.toSignal(signal)); | ||
SymSignal result = spySignalsClient.updateSignal(signal.getId(), signal); | ||
assertEquals(SymSignalTest.DUMMY_ID, result.getId()); | ||
} | ||
|
||
@Test | ||
public void deleteSignalTest() throws Exception { | ||
SymSignal signal = new SymSignal(); | ||
signal.setName(SymSignalTest.DUMMY_NAME); | ||
signal.setQuery(SymSignalTest.DUMMY_QUERY); | ||
signal.setId(SymSignalTest.DUMMY_ID); | ||
SuccessResponse resp=new SuccessResponse(); | ||
when(api.v1SignalsIdDeletePost(anyString(), anyString(), anyString())).thenReturn(resp); | ||
spySignalsClient.deleteSignal(signal.getId()); | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
symphony-client/src/test/java/org/symphonyoss/symphony/clients/model/SymSignalTest.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,83 @@ | ||
package org.symphonyoss.symphony.clients.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.symphonyoss.symphony.agent.model.BaseSignal; | ||
import org.symphonyoss.symphony.agent.model.Signal; | ||
import org.symphonyoss.symphony.agent.model.SignalList; | ||
|
||
public class SymSignalTest { | ||
public static final String DUMMY_ID = "dummy_id"; | ||
public static final String DUMMY_QUERY = "HASHTAG:dummy AND CASHTAG:query"; | ||
public static final String DUMMY_NAME = "Dummy Name for signal"; | ||
public static final Boolean COMPANY_WIDE = false; | ||
public static final Boolean VISIBLE_ON_PROFILE = true; | ||
|
||
public void compareSignalToSymSignal(Signal sig, SymSignal symSig) { | ||
assertEquals(sig.getId(), symSig.getId()); | ||
assertEquals(sig.getName(), symSig.getName()); | ||
assertEquals(sig.getQuery(), symSig.getQuery()); | ||
assertEquals(sig.getCompanyWide(), symSig.getCompanyWide()); | ||
assertEquals(sig.getVisibleOnProfile(), symSig.getVisibleOnProfile()); | ||
} | ||
|
||
public void compareBaseSignalToSymSignal(BaseSignal sig, SymSignal symSig) { | ||
assertEquals(sig.getName(), symSig.getName()); | ||
assertEquals(sig.getQuery(), symSig.getQuery()); | ||
assertEquals(sig.getCompanyWide(), symSig.getCompanyWide()); | ||
assertEquals(sig.getVisibleOnProfile(), symSig.getVisibleOnProfile()); | ||
} | ||
|
||
@Test | ||
public void testToSymSignal() { | ||
Signal sig = new Signal(); | ||
sig.id(DUMMY_ID); | ||
sig.name(DUMMY_NAME); | ||
sig.query(DUMMY_QUERY); | ||
sig.companyWide(COMPANY_WIDE); | ||
sig.visibleOnProfile(VISIBLE_ON_PROFILE); | ||
SymSignal symSig = SymSignal.toSymSignal(sig); | ||
compareSignalToSymSignal(sig, symSig); | ||
} | ||
|
||
@Test | ||
public void testFromSymSignal() { | ||
SymSignal symSig = new SymSignal(); | ||
symSig.setId(DUMMY_ID); | ||
symSig.setName(DUMMY_NAME); | ||
symSig.setQuery(DUMMY_QUERY); | ||
symSig.setCompanyWide(COMPANY_WIDE); | ||
symSig.setVisibleOnProfile(VISIBLE_ON_PROFILE); | ||
Signal sig = SymSignal.toSignal(symSig); | ||
compareSignalToSymSignal(sig, symSig); | ||
} | ||
|
||
@Test | ||
public void toBaseSignalTest() { | ||
SymSignal symSig = new SymSignal(); | ||
symSig.setName(DUMMY_NAME); | ||
symSig.setQuery(DUMMY_QUERY); | ||
symSig.setCompanyWide(COMPANY_WIDE); | ||
symSig.setVisibleOnProfile(VISIBLE_ON_PROFILE); | ||
BaseSignal sig = SymSignal.toBaseSignal(symSig); | ||
compareBaseSignalToSymSignal(sig, symSig); | ||
} | ||
|
||
@Test | ||
public void toSignalListTest() { | ||
SignalList sigList=new SignalList(); | ||
Signal sig = new Signal(); | ||
sig.id(DUMMY_ID); | ||
sig.name(DUMMY_NAME); | ||
sig.query(DUMMY_QUERY); | ||
sig.companyWide(COMPANY_WIDE); | ||
sig.visibleOnProfile(VISIBLE_ON_PROFILE); | ||
sigList.add(sig); | ||
List<SymSignal> sigs=SymSignal.fromSignalList(sigList); | ||
SymSignal symSig=sigs.get(0); | ||
compareSignalToSymSignal(sig, symSig); | ||
} | ||
} |