Vous êtes sur la page 1sur 6

EXAMEN

Semestre : 1 2 X
Session : Principale X
Unité d’enseignement : Architecture N-tiers ………………………………………
Modules : Famework Spring - Architecture N-tiers .NET - Architecture Orientée Service « SOA »
Classe(s) : 4INFOB
Nombre de questions : 42 questions

Documents autorisés : OUI NON X Nombre de pages : ..

Calculatrice autorisée : OUI NON X Internet autorisée : OUI NON X


Date : …02/07/2020……………… Heure ........ ...10h45....... Durée :....1h30.....

Partie I : Framework Spring [14 questions]

[Spring Boot - Spring Core - Spring Data JPA - Spring MVC REST - Log4J -AOP – JSF]
Toutes les questions sont à réponse unique.

1 : On se propose de mettre en place une application de gestion - L’association bidirectionnelle Candidat-Examen


d’une auto-école. indique qu’un candidat peut passer plusieurs
Ci-dessous, le diagramme de classes. examens et qu’un examen peut être passé par un
seul candidat à une date donnée.
- L’association bidirectionnelle Candidat-
SeanceDeFormation indique qu’un candidat peut
assister à une ou plusieurs séances de formation.
- L’énumération doit être stockée en tant que
chaîne de caractères dans la base.

D'après le diagramme de classes, quel est le nombre de


tables générées ? (/1pt)

A. 3

B. 4

C. 5

D. 6
- Les identifiants sont auto-générés avec la stratégie
«IDENTITY».

1/6
2 : Compléter QI.2. (/1pt) 3 : Compléter QI.3. (/1pt)
@Entity
public class Candidat implements Serializable {
@Entity
@Id
public class Examen implements Serializable
@GeneratedValue(strategy=GenerationType.IDENTITY)
{ @Id
private int idCd;
@GeneratedValue(strategy=GenerationType.IDENT
ITY)
private String login;
private int idEx;
private String pwd;
@Temporal(TemporalType.DATE)
private int budgetFormations;
private Date dateExamen;

@Enumerated(EnumType.STRING)
@ QI.2. ….
neToMany(mappedBy="candidat")
List
O <Examen> examens; Type type;
} @ManyToOne
}
QI.3. Candidat
…. candidat;
A. @OneToMany(mappedBy="candidat")
A. private List <Candidat> candidats;
B. @ManyToOne(mappedBy="candidat")
B. private Candidat candidat;
C. @OneToMany
C. a et b sont possibles
D. @ManyToOne
D. Aucune réponse

4 : Les services sont les suivants. Tous les services sont exposés avec Spring REST MVC.
Compléter QI.4. (/1pt)
public interface ICandidatService {

public void ajouterCandidat(Candidat candidat);


public void affecterExamenACandidat(int cdId, int exId);
public void affecterSeanceDeFormationACandidat(int cdId, int idex);
public List<SeanceDeFormation> listerFormations(int cdId);
public Candidat getCandidatByLoginAndPassword(String login, String password) ;
public void reussirExamen(int idex);
public List<Examen> listerExamens(int cdId);
public void desaffecterSeanceDeFormationACandidat(int idcd, int idsf);}

@RestController
public class RestControlCandidat
{ @Autowired
ICandidatService icandidatservice;
@Autowired
IExamService iexamenservice;
@Autowired
ISeanceDeFormation iseanceformation;

// http://localhost:8083/affecterExamenACandidat/1/1

QI.4.@PutMapping
…. (value = "/affecterExamenACandidat/{idcdt}/{idex}")
public void affecterExamenACandidat(@PathVariable("idcdt")int cdId,
@PathVariable("idex")int exId) {
icandidatservice.affecterExamenACandidat(cdId, exId);}}
2/6
A. @PostMapping

B. @PutMapping

C. @GetMapping

D. @DeleteMapping

5 : Service : Nous allons affecter une séance de formation, pour laquelle on a des places disponibles,
au candidat Ali selon le type de son examen et à une date antérieure à sa date d’examen. Après
affectation, nous allons mettre jour les places disponibles et le budget du candidat.
En premier lieu, nous avons besoin de chercher la formation correspondante. Compléter QI.5. (/1pt)

@Repository
public interface CandidatRepository extends CrudRepository<Candidat, Integer> {

QI.5 sf from SeanceDeFormation sf where sf.type=:typeex


@Query(" Select ")
and
public SeanceDeFormation "typeex") Type
getSeanceDeFormation( @Param(
typeex, ("d") Date d);
@Param
}
A. Select SeanceDeFormation sf where sf.type=:typeex and sf.dateSeance<:d and sf.nbPlaceLibre>0
B. Select sf from SeanceDeFormation sf where sf.type=:typeex or sf.dateSeance<:d
or sf.nbPlaceLibre>0
C. Select sf from SeanceDeFormation sf where sf.type=:typeex and sf.dateSeance<:d
andsf.nbPlaceLibre>0
D. Aucune réponse n’est correcte.
6 : Compléter QI.6. (/1pt)

@Repository
public interface CandidatRepository extends CrudRepository<Candidat, Integer> {

@Query(" Select sf from SeanceDeFormation sf where ")


sf.type=:typeex
public SeanceDeFormation ("typeex") Type
QI.6
@Param
getSeanceDeFormation(
typeex, QI.6 ("d") Date d);
@Param
}
A. @PathVariable
B. @Param
C. @QueryParam
D. @ParamQuery

3/6
7 : Authentification (login.xhtml): Le formulaire accepte un login login.xhtml
et un mot de passe, affiche un message d’erreur en cas d’une <h:form id="form">
éventuelle erreur d’identification et oriente l’utilisateur vers son <b>Connexion</b>
espace. <h:panelGrid columns="2">
<h:outputText value="Login" />
<h:inputText
value="#{candidatController
QI.7 .login}" />
<h:outputText value="Mot de passe" />
<h:inputSecret
value="#{candidatController
QI.7 .pwd}" />
<h:commandButton id="btn" value="Connexion"
Espace Utilisateur (welcome.xhtml) : Après authentification, action="#{candidatController
QI.7 .dologin}" />
l’utilisateur peut visualiser ses formations. Il peut aussi refuser une <h:message for="btn"/>
formation. L’accès à cette page est sécurisé en utilisant un filtre </h:panelGrid>
d’authentification. </h:form>

A. candidatController

B. iControllerCandidatImpl

C. IControllerCandidatImpl

D. Réponses b et c
8 : Voici une partie du code de
welcome.xhtml. Compléter QI.8. (/1pt)
<h:panelGroup>
<h:form>
Étant donné ce Controller, compléter QI.7. (/1pt)
<h:outputText value="Bonjour #{candidatCo }"
/>
@Scope(value = "session") <b>Bienvenue à ton espace.</b>
@ELBeanName(value = "candidatController") <b>Voici tes formations planifiées. </b>
@Join(path = "/", to = "/login.jsf") <br />
@Controller <h:dataTable value="#{candidatController.
public class IControllerCandidatImpl { listerFormations(1)}" var="sf">
@Autowired <h:column>
ICandidatService icandidatservice; <f:facet name="header">
<h:outputText value="Date" />
private String login;
</f:facet>
private String pwd;
<h:outputText value="#{sf.dateSeance
QI.8 }"/>
private Candidat candidat; </h:column>
private Boolean loggedIn; ……….
</h:dataTable>
public String dologin()
{ String navigateTo = "null"; <h:commandLink value="Déconnexion" action=
candidat=icandidatservice.getCandidatBy "#{candidatController .doLogout()}" />
LoginAndPassword(login, pwd); </h:form>
if (candidat != null ) { </h:panelGroup>
navigateTo = "/welcome.xhtml?faces-redirect=true";
loggedIn = true; } return navigateTo; } }
A. Formation.dateSeance
B. sf.dateSeance
C. candidatController.dateSeance
D. Aucune réponse

4/6
9 : Nous avons ajouté un filtre d’authentification à notre application. Compléter QI.9. (/1pt)
public class LoginFilter implements Filter {

public void doFilter(ServletRequest request, ServletResponse response,


FilterChain chain) throws IOException, ServletException {
HttpServletRequest hrequest= (HttpServletRequest)request;
HttpServletResponse hresponse= (HttpServletResponse)response;
IControllerCandidatImpl candidatcontroller=(IControllerCandidatImpl)
hrequest.getSession().getAttribute("candidatController");
if(candidatcontroller!=null && candidatcontroller.getLoggedIn())

{chain.doFilter(request, }
QI.9
response);
else
{ hresponse.sendRedirect(hrequest.getContextPath()
+"/");
}}
}

A. Aucune réponse n’est correcte.

B. request.doFilter(request, response);

C. response.doFilter(request, response);

D. chain.doFilter(request, response);
10 : Nous avons ajouté à notre projet un aspect qui calcule et affiche dans les logs le temps d’exécution
de chaque méthode des services. Compléter QI.10 (/1pt).
@Component
@Aspect
public class PerformanceAspect
{ private static final Logger logger =
LogManager.getLogger(PerformanceAspect.class);

QI.10
@Aroun ("execution(* tn.esprit.spring.services.*.*(..))")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
long start = System.currentTimeMillis();
Object out=pjp.proceed();
long elapsedTime = System.currentTimeMillis() - start;
logger.info("Method execution time: " + elapsedTime + "
milliseconds.");
return out;
}}

A. @Before("execution(* tn.esprit.spring.services.*.*(..))")

5/6
B. @After("execution(* tn.esprit.spring.services.*.*(..))")

C. @Around("execution(* tn.esprit.spring.services.*.*(..))")

D. A et B

11 : Erreur1 : C'est quoi la cause de cette erreur ? Le


développeur a oublié de mettre (/1pt): 13 : Erreur 3 : C’est quoi la cause de cette erreur ? (/1pt)
Description:
Field icandidatservice in
Caused by: org.hibernate.AnnotationException:
tn.esprit.spring.controller.RestControlCandidat
@OneToOne or @ManyToOne on required a bean of type
tn.esprit.spring.entities.Examen.candidat references an 'tn.esprit.spring.services.ICandidatService'
unknown entity: tn.esprit.spring.entities.Candidat that could not be found.
The injection point has the following
A. @Id annotations:
@org.springframework.beans.factory.annotation.
Autowired(required=true)
B. @Entity

C. @OneToMany A. Le développeur a oublié d’annoter la classe


RestControlCandidat par l’annotation @RestController
D. @ManyToOne
B. Le développeur a oublié d’annoter
12 : Erreur 2 : C’est quoi la cause la plus probable de cette l’objetICandidatService icandidatservice ; par
erreur ? (/1pt) l’annotation @Autowired
C. Le développeur a oublié d’annoter la classe
com.mysql.cj.jdbc.exceptions.CommunicationsException: CandidatServiceImpl par l’annotation @Service
D. a et b
Communications link failure
The last packet sent successfully to the server was 0
14 : Erreur 4 : C’est quoi la cause de cette erreur ? (/1pt)
milliseconds ago.
javax.el.PropertyNotFoundException: Target Unreachable,
The driver has not received any packets from the server.
At com.mysql.cj.jdbc.exceptions.SQLError. identifier [candidatControllerTest] resolved to null
createCommunicationsException(SQLError.java:174) at org.apache.el.parser.AstValue.getTarget
~[mysql-connector-java-8.0.18.jar:8.0.18] (AstValue.java:74) ~[tomcat-embed-el-9.0.27.jar:9.0.27] at
org.apache.el.parser.AstValue.getType (AstValue.java:58)
A. Le développeur a oublié de créer la base de données. ~[tomcat-embed-el-9.0.27.jar:9.0.27] at
org.apache.el.ValueExpressionImpl.getType
B. Le développeur a oublié d’annoter les entités (ValueExpressionImpl.java:174) ~[tomcat-embed-el-
par l’annotation @Entity 9.0.27.jar:9.0.27]

C. Le développeur a mis un numéro de port erroné A. Le développeur a oublié de vider le dossier Target
pourl’accès au serveur de données
B. Le développeur a oublié de créer le dossier Target
D. Aucune réponse n’est correcte
C. Le développeur a mis un nom erroné de
sonController

D. Aucune réponse n’est correcte.

6/6

Vous aimerez peut-être aussi