-
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.
- Loading branch information
1 parent
cdfdf30
commit 50ca8b2
Showing
11 changed files
with
163 additions
and
32 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
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
57 changes: 57 additions & 0 deletions
57
src/test/java/ch/stephan/chickenfarm/mqtt/MockedMqttConfig.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,57 @@ | ||
package ch.stephan.chickenfarm.mqtt; | ||
|
||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.integration.annotation.ServiceActivator; | ||
import org.springframework.integration.core.MessageProducer; | ||
import org.springframework.integration.mqtt.core.MqttPahoClientFactory; | ||
import org.springframework.messaging.MessageChannel; | ||
import org.springframework.messaging.MessageHandler; | ||
|
||
import ch.stephan.chickenfarm.registry.BoxService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
@Profile({ "maven", "dev" }) | ||
public class MockedMqttConfig { | ||
|
||
@MockBean | ||
private BoxService boxService; | ||
|
||
@MockBean | ||
private MessageChannel mqttInputChannel; | ||
|
||
@MockBean | ||
private MqttPahoClientFactory mqttClientFactory; | ||
|
||
@MockBean | ||
private MessageProducer inbound; | ||
|
||
@MockBean | ||
private MessageHandler handler; | ||
|
||
@Bean | ||
MessageChannel mqttInputChannel() { | ||
return mqttInputChannel; | ||
} | ||
|
||
@Bean | ||
MqttPahoClientFactory mqttClientFactory() { | ||
return mqttClientFactory; | ||
} | ||
|
||
@Bean | ||
MessageProducer inbound() { | ||
return inbound; | ||
} | ||
|
||
@Bean | ||
@ServiceActivator(inputChannel = "mqttInputChannel") | ||
MessageHandler handler() { | ||
return handler; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/ch/stephan/chickenfarm/mqtt/MockedMqttConfiguration.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,22 @@ | ||
package ch.stephan.chickenfarm.mqtt; | ||
|
||
import org.eclipse.paho.client.mqttv3.IMqttClient; | ||
import org.eclipse.paho.client.mqttv3.MqttException; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Profile({ "maven", "dev" }) | ||
@Configuration | ||
public class MockedMqttConfiguration { | ||
|
||
@MockBean | ||
private IMqttClient mqttClient; | ||
|
||
@Bean | ||
IMqttClient mqttClient() throws MqttException { | ||
return mqttClient; | ||
} | ||
|
||
} |
49 changes: 42 additions & 7 deletions
49
src/test/java/ch/stephan/chickenfarm/scale/ScaleServiceTest.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 |
---|---|---|
@@ -1,27 +1,62 @@ | ||
package ch.stephan.chickenfarm.scale; | ||
|
||
import java.util.UUID; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import ch.stephan.chickenfarm.mqtt.MqttPublisherService; | ||
import ch.stephan.chickenfarm.registry.BoxService; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ScaleServiceTest { | ||
private static final String UID = UUID.randomUUID().toString(); | ||
|
||
private static final String BOX_ID = "2"; | ||
|
||
private ScaleService scaleService; | ||
|
||
@InjectMocks | ||
private BoxService boxService; | ||
|
||
@Mock | ||
private MqttPublisherService mqttPublisherService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
scaleService = new ScaleService(); | ||
MockitoAnnotations.openMocks(this); | ||
|
||
boxService.initBoxes(); | ||
|
||
scaleService = new ScaleService(boxService, mqttPublisherService); | ||
} | ||
|
||
@Test | ||
void measureWeight() { | ||
int expectedWeight = 85; | ||
|
||
boxService.getBox(BOX_ID).setWeight(expectedWeight); | ||
int result = scaleService.measureWeight(BOX_ID); | ||
|
||
assertEquals(expectedWeight, result); | ||
} | ||
|
||
@Test | ||
void test() { | ||
// when(mockedIpConnection.).thenReturn(discoveries); | ||
void calibrate() { | ||
String result = scaleService.calibrate(BOX_ID); | ||
|
||
// int result = scaleService.measureWeight(UID); | ||
assertEquals("successfully calibrated", result); | ||
} | ||
|
||
@Test | ||
void tare() { | ||
String result = scaleService.tare(BOX_ID); | ||
|
||
// fail("Not yet implemented"); | ||
assertEquals("successfully tared", result); | ||
} | ||
|
||
} |
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