Commit 5edd0c23 authored by abbenhoumi's avatar abbenhoumi

Merge branch 'develop' into 'master'

Develop

See merge request !3
parents ca987b93 efe24365
......@@ -54,20 +54,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
<build>
......
package isima.f2.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
public static final String[] PUBLIC_MATCHES = {
"**/**"
};
@Override
public void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.antMatchers(PUBLIC_MATCHES).permitAll();
}
/*
@Override
protected void configure(HttpSecurity http) throws Exception {
http
//HTTP Basic authentication
.httpBasic()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/actions/**").hasRole("USER")
.antMatchers(HttpMethod.POST, "/actions").hasRole("ADMIN")
.antMatchers(HttpMethod.PUT, "/actions/**").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH, "/actions/**").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE, "/actions/**").hasRole("ADMIN")
.and()
.csrf().disable()
.formLogin().disable();
}
*/
// 2 utilisateur pour le demos
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("{noop}password").roles("USER")
.and()
.withUser("admin").password("{noop}password").roles("USER", "ADMIN");
}
}
......@@ -11,4 +11,5 @@ public interface IPoubelle {
public Poubelle modifierPoubelle(Poubelle poubelle);
public Optional<Poubelle> getPoubelle(Long id);
public List<Poubelle> getPoubelles();
public void viderPoubelle(long id);
}
package isima.f2.controllers;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
......@@ -8,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import isima.f2.model.Poubelle;
import isima.f2.services.ImpPoubelle;
......@@ -28,4 +31,18 @@ public class PoubelleController {
public Poubelle savePoubelle(@RequestBody Poubelle poubelle) {
return poubelles.ajouterPoubelle(poubelle);
}
@PostMapping ("/vider")
@ResponseBody
public String viderPoubelle(@RequestParam Map <String, String> allParams) {
long id = Long.parseLong(allParams.get("id"));
poubelles.viderPoubelle(id);
return "La poubelle a été vidée avec succes";
}
@PostMapping ("/testpost")
@ResponseBody
public String testpost(@RequestParam Map <String, String> allParams) {
return "Les paramètres sont"+ allParams.entrySet ();
}
}
package isima.f2.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import isima.f2.model.Poubelle;
public interface IPoubelleDAO extends JpaRepository<Poubelle, Long> {
@Modifying
@Transactional
@Query("UPDATE Poubelle p SET p.contenu = 0 WHERE p.id = :id")
int updatePoubelleSetCapacityZero(@Param("id") long id);
}
......@@ -41,6 +41,7 @@ public class Poubelle implements Serializable{
public Poubelle() {
super();
}
public Poubelle(Long id, Double longitude, Double latitude, Double capacity) {
super();
this.id = id;
......
......@@ -41,4 +41,9 @@ public class ImpPoubelle implements IPoubelle{
return poubelleDAO.findAll();
}
@Override
public void viderPoubelle(long id){
poubelleDAO.updatePoubelleSetCapacityZero(id);
}
}
package isima.F2;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
@SpringBootTest
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class RamassagePoubleDepotApplicationTests {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Test
void contextLoads() {
public void testRunServerRamassageAppTest() throws Exception {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/",
String.class)).isNotEmpty();
}
}
package isima.F2.controller;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import isima.f2.controllers.PoubelleController;
import isima.f2.model.Poubelle;
import isima.f2.services.ImpPoubelle;
@WebMvcTest(PoubelleController.class)
public class PoubelleControllerTest {
@MockBean
private ImpPoubelle service;
@Autowired
private MockMvc mockMvc;
@Test
public void verificationGetPoubellesMethode() throws Exception {
List<Poubelle> listRes = new ArrayList();
listRes.add(new Poubelle());
//Return null car Il n'y pas une initialisation de constructeur
when(service.getPoubelles()).thenReturn(listRes);
this.mockMvc.perform(get("/poubelles/")).andDo(print()).andExpect(status().isOk())
.andExpect(content().string(containsString("\"id\":null")));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment