owner fix
This commit is contained in:
parent
2d0e06bfce
commit
ef9daa5d4f
3 changed files with 121 additions and 70 deletions
|
@ -1,69 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.sap</groupId>
|
||||
<artifactId>tamagotchi-service</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<groupId>com.sap</groupId>
|
||||
<artifactId>tamagotchi-service</artifactId>
|
||||
<version>0.1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.6.RELEASE</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.6.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud</groupId>
|
||||
<artifactId>libraries-bom</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud</groupId>
|
||||
<artifactId>libraries-bom</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud</groupId>
|
||||
<artifactId>google-cloud-pubsub</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud</groupId>
|
||||
<artifactId>google-cloud-pubsub</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-maven-plugin</artifactId>
|
||||
<version>1.9.77</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-maven-plugin</artifactId>
|
||||
<version>1.9.77</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -3,14 +3,15 @@
|
|||
*/
|
||||
package com.sap.tamagotchi.model;
|
||||
|
||||
import com.sap.tamagotchi.service.TamagotchiService;
|
||||
import static com.sap.tamagotchi.service.TamagotchiService.DEVICE_EVENT_PROCESSOR_SCHEDULE;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.sap.tamagotchi.service.TamagotchiService.DEVICE_EVENT_PROCESSOR_SCHEDULE;
|
||||
import com.sap.tamagotchi.service.TamagotchiService;
|
||||
|
||||
@Service
|
||||
@EnableScheduling
|
||||
public class Owner {
|
||||
|
||||
private TamagotchiService tamagotchiService;
|
||||
|
@ -23,13 +24,23 @@ public class Owner {
|
|||
@Scheduled(fixedDelay = DEVICE_EVENT_PROCESSOR_SCHEDULE)
|
||||
public void setData() {
|
||||
for (Device d : tamagotchiService.getDevices()) {
|
||||
double random = Math.random();
|
||||
|
||||
String userName = d.getOwner().substring(0, d.getOwner().indexOf("@")).toUpperCase();
|
||||
|
||||
int careAboutThePet = 0;
|
||||
|
||||
for (int i = 0; i < userName.length(); i++) {
|
||||
if (d.getColor().toString().indexOf(userName.charAt(i)) != -1) {
|
||||
careAboutThePet++;
|
||||
}
|
||||
}
|
||||
|
||||
Care care = new Care();
|
||||
|
||||
if (random <= 0.5) {
|
||||
care.setFeed(-(int) (random * 10));
|
||||
if (careAboutThePet == 0) {
|
||||
care.setFeed(-5);
|
||||
} else {
|
||||
care.setFeed((int) (random * 10));
|
||||
care.setFeed(5);
|
||||
}
|
||||
tamagotchiService.takeCare(d.getId(), care);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,40 @@
|
|||
/**
|
||||
* Copyright (c) 2019, SAP SE, All rights reserved.
|
||||
*/
|
||||
package com.sap.tamagotchi.model;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.util.Collection;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import com.sap.tamagotchi.service.TamagotchiService;;
|
||||
|
||||
class OwnerTest {
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class OwnerTest {
|
||||
|
||||
}
|
||||
@Autowired
|
||||
Owner owner;
|
||||
|
||||
@MockBean
|
||||
TamagotchiService tamagotchiService;
|
||||
|
||||
Collection<Device> mockDevices;
|
||||
|
||||
// @Before
|
||||
// public void init() {
|
||||
// MockitoAnnotations.initMocks(this);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testIt() {
|
||||
when(tamagotchiService.getDevices()).thenReturn(asList(new Device("elisa@sap.com", Color.BLUE)));
|
||||
owner.setData();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue