Skip to content

tarefa extra classe aula.01 #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,34 @@
@AutoConfigureMockMvc
public class GreetingControllerTests {

/* O trecho destacado na classe GreetingControllerTests utiliza a anotação @Autowired para injetar uma
instância de MockMvc. Essa classe é usada para simular requisições HTTP e testar endpoints do controlador
GreetingController sem a necessidade de iniciar um servidor real.
No contexto da classe, o MockMvc é usado em dois testes:

noParamGreetingShouldReturnDefaultMessage: Verifica se o endpoint /greeting retorna a mensagem padrão "Hello, World!" quando nenhum parâmetro é fornecido.
paramGreetingShouldReturnTailoredMessage: Verifica se o endpoint retorna uma mensagem personalizada quando o parâmetro name é fornecido.
Esses testes garantem que o controlador responde corretamente às requisições simuladas.
*/
@Autowired
private MockMvc mockMvc;

/* O método noParamGreetingShouldReturnDefaultMessage é um teste que verifica o comportamento do endpoint /greeting quando nenhum parâmetro é fornecido. Ele utiliza o MockMvc para simular uma requisição HTTP GET e valida que: O status da resposta é 200 OK (andExpect(status().isOk())).
O corpo da resposta JSON contém o campo content com o valor "Hello, World!" (andExpect(jsonPath("$.content").value("Hello, World!"))).
Esse teste garante que o controlador retorna a mensagem padrão corretamente em cenários sem parâmetros. */
@Test
public void noParamGreetingShouldReturnDefaultMessage() throws Exception {

this.mockMvc.perform(get("/greeting")).andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.content").value("Hello, World!"));
}

/*
O método paramGreetingShouldReturnTailoredMessage é um teste que verifica o comportamento do endpoint /greeting quando o parâmetro name é fornecido. Ele utiliza o MockMvc para simular uma requisição HTTP GET com o parâmetro name definido como "Spring Community" e valida que:
O status da resposta é 200 OK (andExpect(status().isOk())).
O corpo da resposta JSON contém o campo content com o valor "Hello, Spring Community!" (andExpect(jsonPath("$.content").value("Hello, Spring Community!"))).
Esse teste garante que o controlador retorna uma mensagem personalizada corretamente quando o parâmetro é fornecido.
*/
@Test
public void paramGreetingShouldReturnTailoredMessage() throws Exception {

Expand Down
42 changes: 42 additions & 0 deletions test/Untitled Diagram.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0" version="26.1.1">
<diagram id="prtHgNgQTEPvFCAcTncT" name="Page-1">
<mxGraphModel dx="1223" dy="871" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="dNxyNK7c78bLwvsdeMH5-11" value="Orgchart" style="swimlane;html=1;startSize=20;horizontal=1;containerType=tree;glass=0;" parent="1" vertex="1">
<mxGeometry x="40" y="80" width="710" height="290" as="geometry" />
</mxCell>
<UserObject label="%name%&lt;br&gt;&lt;i style=&quot;color: gray&quot;&gt;%position%&lt;/i&gt;&lt;br&gt;&lt;a href=&quot;mailto:%email%&quot;&gt;Email&lt;/a&gt;" name="Tessa Miller" position="CFO" location="Office 1" email="[email protected]" placeholders="1" link="https://www.draw.io" id="dNxyNK7c78bLwvsdeMH5-12">
<mxCell style="label;image=https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-3-128.png;whiteSpace=wrap;html=1;rounded=0;glass=0;treeMoving=1;treeFolding=1;" parent="dNxyNK7c78bLwvsdeMH5-11" vertex="1">
<mxGeometry x="260" y="50" width="180" height="70" as="geometry" />
</mxCell>
</UserObject>
<mxCell id="dNxyNK7c78bLwvsdeMH5-13" value="" style="endArrow=blockThin;endFill=1;fontSize=11;edgeStyle=elbowEdgeStyle;elbow=vertical;rounded=0;" parent="dNxyNK7c78bLwvsdeMH5-11" source="dNxyNK7c78bLwvsdeMH5-12" target="dNxyNK7c78bLwvsdeMH5-14" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<UserObject label="%name%&lt;br&gt;&lt;i style=&quot;color: gray&quot;&gt;%position%&lt;/i&gt;&lt;br&gt;&lt;a href=&quot;mailto:%email%&quot;&gt;Email&lt;/a&gt;" name="Edward Morrison" position="Brand Manager" location="Office 2" email="[email protected]" placeholders="1" link="https://www.draw.io" id="dNxyNK7c78bLwvsdeMH5-14">
<mxCell style="label;image=https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-10-3-128.png;whiteSpace=wrap;html=1;rounded=0;glass=0;treeFolding=1;treeMoving=1;" parent="dNxyNK7c78bLwvsdeMH5-11" vertex="1">
<mxGeometry x="40" y="180" width="180" height="80" as="geometry" />
</mxCell>
</UserObject>
<mxCell id="dNxyNK7c78bLwvsdeMH5-15" value="" style="endArrow=blockThin;endFill=1;fontSize=11;edgeStyle=elbowEdgeStyle;elbow=vertical;rounded=0;" parent="dNxyNK7c78bLwvsdeMH5-11" source="dNxyNK7c78bLwvsdeMH5-12" target="dNxyNK7c78bLwvsdeMH5-16" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<UserObject label="%name%&lt;br&gt;&lt;i style=&quot;color: gray&quot;&gt;%position%&lt;/i&gt;&lt;br&gt;&lt;a href=&quot;mailto:%email%&quot;&gt;Email&lt;/a&gt;" name="Evan Valet" position="HR Director" location="Office 4" email="[email protected]" placeholders="1" link="https://www.draw.io" id="dNxyNK7c78bLwvsdeMH5-16">
<mxCell style="label;image=https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-9-2-128.png;whiteSpace=wrap;html=1;rounded=0;glass=0;treeFolding=1;treeMoving=1;" parent="dNxyNK7c78bLwvsdeMH5-11" vertex="1">
<mxGeometry x="260" y="180" width="180" height="80" as="geometry" />
</mxCell>
</UserObject>
<mxCell id="dNxyNK7c78bLwvsdeMH5-17" value="" style="endArrow=blockThin;endFill=1;fontSize=11;edgeStyle=elbowEdgeStyle;elbow=vertical;rounded=0;" parent="dNxyNK7c78bLwvsdeMH5-11" source="dNxyNK7c78bLwvsdeMH5-12" target="dNxyNK7c78bLwvsdeMH5-18" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<UserObject label="%name%&lt;br&gt;&lt;i style=&quot;color: gray&quot;&gt;%position%&lt;/i&gt;&lt;br&gt;&lt;a href=&quot;mailto:%email%&quot;&gt;Email&lt;/a&gt;" name="Alison Donovan" position="System Admin" location="Office 3" email="[email protected]" placeholders="1" link="https://www.draw.io" id="dNxyNK7c78bLwvsdeMH5-18">
<mxCell style="label;image=https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-2-128.png;whiteSpace=wrap;html=1;rounded=0;glass=0;" parent="dNxyNK7c78bLwvsdeMH5-11" vertex="1">
<mxGeometry x="490" y="180" width="180" height="80" as="geometry" />
</mxCell>
</UserObject>
</root>
</mxGraphModel>
</diagram>
</mxfile>