Skip to content

Commit

Permalink
MNBService Test + Readme and pom fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
devshiro committed May 28, 2017
1 parent f14979b commit 0ff8db4
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 12 deletions.
50 changes: 49 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
# OpenFleet
Openfleet is a Java web application developed using the Spring framework to help in the management of micro and small
transportation businesses.

[![Build Status](https://travis-ci.org/Chrams/openfleet.svg?branch=master)](https://travis-ci.org/Chrams/openfleet)
[![codecov](https://codecov.io/gh/Chrams/openfleet/branch/master/graph/badge.svg)](https://codecov.io/gh/Chrams/openfleet)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/01f0f9c60c5545aaa95cce793547a3b0)](https://www.codacy.com/app/Chrams/openfleet?utm_source=github.com&utm_medium=referral&utm_content=Chrams/openfleet&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/01f0f9c60c5545aaa95cce793547a3b0)](https://www.codacy.com/app/Chrams/openfleet?utm_source=github.com&utm_medium=referral&utm_content=Chrams/openfleet&utm_campaign=Badge_Grade)

### Usage
Run using spring-boot:

```
mvn spring-boot:run
```

Create executable uberjar:

```
mvn package
```

Generate site documentations:

```
mvn site
```

The embedded LDAP server hase a single user. You can login using:
* username: admin
* password: password

### Configurations
All application configurations are currently stored in the
[application.properties](https://github.com/Chrams/openfleet/blob/master/src/main/resources/application.properties) file.
#### LDAP Server configuration
To use other than the embedded LDAP server, you'll need to specifiy your LDAP server's url and base in the configuration file.
Example:
```
ldap.contextSource.url=ldap://localhost:389
ldap.contextSource.base=cn=Users,dc=test,dc=local
```
#### Database configuration
This application does not come with embedded relational database service. So you'll need to provide your own.
To do that you'll need to modify the configuration file accordingly:
```
spring.datasource.url = jdbc:protocol:the.url.of.your.dbserver/yourschema
spring.datasource.username = yourUsername
spring.datasource.password = yourPassword
spring.datasource.driverClassName = your.dbservers.jdbc.driver
```
### Disclaimer
Since this was a school project, no further development is planned yet.
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,6 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2</version>
</dependency>
JAX-WS
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private void generateExchangeRates(){
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
logger.debug(this.service.getCurrentExchangeRates());
this.exchangeRates = builder.parse(new InputSource(new StringReader(this.service.getCurrentExchangeRates())));
this.exchangeRates.getDocumentElement().normalize();
} catch(Exception e)
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/tests/services/ExchangeServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tests.services;

import com.markbudai.openfleet.services.ExchangeService;
import com.markbudai.openfleet.services.implementations.MNBExchangeService;
import mnb.MNBArfolyamServiceSoapGetCurrentExchangeRatesStringFaultFaultMessage;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.util.Currency;

/**
* Created by Mark on 2017. 05. 28..
*/
public class ExchangeServiceTest {
private static ExchangeService exchangeService;



@BeforeClass
public static void init() throws MNBArfolyamServiceSoapGetCurrentExchangeRatesStringFaultFaultMessage, IOException {
mnb.MNBArfolyamServiceSoap mockedSoap = Mockito.mock(mnb.MNBArfolyamServiceSoap.class);
Resource mockedResponse = new ClassPathResource("staticExchangeRate.xml");
String content = new String(Files.readAllBytes(mockedResponse.getFile().toPath()));
Mockito.when(mockedSoap.getCurrentExchangeRates()).thenReturn(content);
exchangeService = new MNBExchangeService(mockedSoap);
}

@Test
public void testUSDRate(){
Assert.assertEquals(273.79,exchangeService.getExchangeRateForCurrency(Currency.getInstance("USD")),0.001);
}

@Test
public void testFromExchangeGetUSDRate(){
Assert.assertEquals(273,exchangeService.exchange(Currency.getInstance("USD"), BigDecimal.valueOf(1),Currency.getInstance("HUF")).longValue());
}

@Test
public void testExchangeFromUSDToEUR(){
Assert.assertEquals(44.54,exchangeService.exchange(Currency.getInstance("USD"),BigDecimal.valueOf(50),Currency.getInstance("EUR")).doubleValue(),0.01);
}

public static void main(String[] args) throws IOException {
System.out.println();
}
}
38 changes: 38 additions & 0 deletions src/test/resources/staticExchangeRate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<MNBCurrentExchangeRates>
<Day date="2017-05-26">
<Rate unit="1" curr="AUD">203,59</Rate>
<Rate unit="1" curr="BGN">157,14</Rate>
<Rate unit="1" curr="BRL">83,6</Rate>
<Rate unit="1" curr="CAD">203,24</Rate>
<Rate unit="1" curr="CHF">282,14</Rate>
<Rate unit="1" curr="CNY">39,89</Rate>
<Rate unit="1" curr="CZK">11,62</Rate>
<Rate unit="1" curr="DKK">41,3</Rate>
<Rate unit="1" curr="EUR">307,33</Rate>
<Rate unit="1" curr="GBP">352,45</Rate>
<Rate unit="1" curr="HKD">35,14</Rate>
<Rate unit="1" curr="HRK">41,41</Rate>
<Rate unit="100" curr="IDR">2,06</Rate>
<Rate unit="1" curr="ILS">76,64</Rate>
<Rate unit="1" curr="INR">4,25</Rate>
<Rate unit="1" curr="ISK">2,73</Rate>
<Rate unit="100" curr="JPY">246,59</Rate>
<Rate unit="100" curr="KRW">24,47</Rate>
<Rate unit="1" curr="MXN">14,79</Rate>
<Rate unit="1" curr="MYR">64,12</Rate>
<Rate unit="1" curr="NOK">32,66</Rate>
<Rate unit="1" curr="NZD">192,86</Rate>
<Rate unit="1" curr="PHP">5,5</Rate>
<Rate unit="1" curr="PLN">73,51</Rate>
<Rate unit="1" curr="RON">67,46</Rate>
<Rate unit="1" curr="RSD">2,5</Rate>
<Rate unit="1" curr="RUB">4,82</Rate>
<Rate unit="1" curr="SEK">31,56</Rate>
<Rate unit="1" curr="SGD">197,85</Rate>
<Rate unit="1" curr="THB">8,04</Rate>
<Rate unit="1" curr="TRY">76,54</Rate>
<Rate unit="1" curr="UAH">10,38</Rate>
<Rate unit="1" curr="USD">273,79</Rate>
<Rate unit="1" curr="ZAR">21,13</Rate>
</Day>
</MNBCurrentExchangeRates>

0 comments on commit 0ff8db4

Please sign in to comment.