package hello;

import static org.junit.Assert.assertEquals;

import java.net.URL;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;


@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest({"server.port=0"})
public class MainControllerTest {

    @Value("${local.server.port}")
    private int port;
    
    @Autowired
    private VoterRepository repository;

    private static final int NUM_VOTER = 4;
    private URL base;
	private RestTemplate template;

	@Before
	public void setUp() throws Exception {
		this.base = new URL("http://localhost:" + port + "/");
		template = new TestRestTemplate();
		
		for (int i = 0; i < NUM_VOTER; i++) {
			repository.save(new Voter("Nombre"+i, "Email"+i, 
					"Password"+i, "Dni"+i));
		}
	}

	@Test
	public void exitenVotantes() throws Exception {
		for (int i = 0; i < NUM_VOTER; i++) {
			assertEquals("Nombre"+i, repository.findByEmailAndPassword("Email"+i,
					"Password"+i).getNombre());
		}
	}
}



























@@ -76,16 +76,91 @@
 et.URL;%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.junit.After;
 %0Aimport 
@@ -1139,23 +1139,15 @@
 ;%0A%0A%09
-@Before%0A%09public
+private
  voi
@@ -1402,17 +1402,16 @@
 %0A%09%09%7D%0A%09%7D%0A
-%0A
 %09@Test%0A%09
@@ -1458,16 +1458,27 @@
 ption %7B%0A
+%09%09setUp();%0A
 %09%09for (i
@@ -1619,16 +1619,487 @@
 ));%0A%09%09%7D%0A
+%09%09repository.deleteAll();%0A%09%7D%0A%09@Test%0A%09public void updatePassword() throws Exception %7B%0A%09%09setUp();%0A%09%09assertEquals(4,repository.count());%0A%09%09Voter votante = repository.findByEmailAndPassword(%22Email1%22,%0A%09%09%09%09%22Password1%22);%0A%09%09assertEquals(%22Nombre1%22, votante.getNombre());%0A%09%09votante.setPassword(%2212%22);%0A%09%09votante=repository.save(votante);%0A%09%09assertEquals(4,repository.count());%0A%09%09assertEquals(votante, repository.findByEmailAndPassword(%22Email1%22,%0A%09%09%09%09%2212%22));%0A%09%09repository.deleteAll();%0A
 %09%7D%0A%7D%0A%0A%0A%0A

Test de actualizar la contraseña