Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Kevin Gilmore 2016-11-23 12:31:00 -06:00
commit 78a130ba67
10 changed files with 140 additions and 19 deletions

View File

@ -0,0 +1,23 @@
package com.baeldung.constructordi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import com.baeldung.constructordi.domain.Engine;
import com.baeldung.constructordi.domain.Transmission;
@Configuration
@ComponentScan("com.baeldung.constructordi")
public class Config {
@Bean
public Engine engine() {
return new Engine("v8", 5);
}
@Bean
public Transmission transmission() {
return new Transmission("sliding");
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.constructordi;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.constructordi.domain.Car;
public class SpringRunner {
public static void main(String[] args) {
Car toyota = getCarFromXml();
System.out.println(toyota);
toyota = getCarFromJavaConfig();
System.out.println(toyota);
}
private static Car getCarFromJavaConfig() {
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
return context.getBean(Car.class);
}
private static Car getCarFromXml() {
ApplicationContext context = new ClassPathXmlApplicationContext("baeldung.xml");
return context.getBean(Car.class);
}
}

View File

@ -0,0 +1,21 @@
package com.baeldung.constructordi.domain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Car {
private Engine engine;
private Transmission transmission;
@Autowired
public Car(Engine engine, Transmission transmission) {
this.engine = engine;
this.transmission = transmission;
}
@Override
public String toString() {
return String.format("Engine: %s Transmission: %s", engine, transmission);
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.constructordi.domain;
public class Engine {
private String type;
private int volume;
public Engine(String type, int volume) {
this.type = type;
this.volume = volume;
}
@Override
public String toString() {
return String.format("%s %d", type, volume);
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.constructordi.domain;
public class Transmission {
private String type;
public Transmission(String type) {
this.type = type;
}
@Override
public String toString() {
return String.format("%s", type);
}
}

View File

@ -0,0 +1,20 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="toyota" class="com.baeldung.constructordi.domain.Car">
<constructor-arg index="0" ref="engine"/>
<constructor-arg index="1" ref="transmission"/>
</bean>
<bean id="engine" class="com.baeldung.constructordi.domain.Engine">
<constructor-arg index="0" value="v4"/>
<constructor-arg index="1" value="2"/>
</bean>
<bean id="transmission" class="com.baeldung.constructordi.domain.Transmission">
<constructor-arg value="sliding"/>
</bean>
</beans>

View File

@ -13,7 +13,7 @@ public class RawDBDemoGeoIPLocationService{
private DatabaseReader dbReader;
public RawDBDemoGeoIPLocationService() throws IOException {
File database = new File("C:\\Users\\Parth Joshi\\Desktop\\GeoLite2-City.mmdb\\GeoLite2-City.mmdb");
File database = new File("your-path-to-db-file");
dbReader = new DatabaseReader.Builder(database).build();
}

View File

@ -77,8 +77,8 @@
<div id="status"></div>
<div id="map" style="height: 500px; width:100%; position:absolute"></div>
<!--AIzaSyDDr65sVtJtlbliOTAeXyZSDPvG9NROjJA -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA4vsDQWHeOrDnzS98XMXl5hgwA9raaQZ8"
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR-MAPS-API-KEY"
async defer></script>
</body>
</html>

View File

@ -15,10 +15,10 @@ public class GeoIpIntegrationTest {
@Test
public void givenIP_whenFetchingCity_thenReturnsCityData() throws IOException, GeoIp2Exception {
File database = new File("C:\\Users\\Parth Joshi\\Desktop\\GeoLite2-City.mmdb\\GeoLite2-City.mmdb");
File database = new File("your-path-to-db-file");
DatabaseReader dbReader = new DatabaseReader.Builder(database).build();
InetAddress ipAddress = InetAddress.getByName("202.47.112.9");
InetAddress ipAddress = InetAddress.getByName("your-public-ip");
CityResponse response = dbReader.city(ipAddress);
String countryName = response.getCountry().getName();

View File

@ -1,11 +1,14 @@
package org.baeldung.okhttp;
import okhttp3.*;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.HttpUrl;
@ -13,7 +16,6 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class OkHttpGetLiveTest {
private static final String BASE_URL = "http://localhost:8080/spring-rest";
@ -23,14 +25,12 @@ public class OkHttpGetLiveTest {
@Before
public void init() {
client = new OkHttpClient();
client = new OkHttpClient();
}
@Test
public void whenGetRequest_thenCorrect() throws IOException {
Request request = new Request.Builder()
.url(BASE_URL + "/date")
.build();
Request request = new Request.Builder().url(BASE_URL + "/date").build();
Call call = client.newCall(request);
Response response = call.execute();
@ -45,9 +45,7 @@ public class OkHttpGetLiveTest {
String url = urlBuilder.build().toString();
Request request = new Request.Builder()
.url(url)
.build();
Request request = new Request.Builder().url(url).build();
Call call = client.newCall(request);
Response response = call.execute();
@ -57,9 +55,7 @@ public class OkHttpGetLiveTest {
@Test
public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException {
Request request = new Request.Builder()
.url(BASE_URL + "/date")
.build();
Request request = new Request.Builder().url(BASE_URL + "/date").build();
Call call = client.newCall(request);
@ -69,7 +65,7 @@ public class OkHttpGetLiveTest {
}
public void onFailure(Call call, IOException e) {
fail();
fail();
}
});