diff --git a/README.md b/README.md
index c58d189..a7394b5 100644
--- a/README.md
+++ b/README.md
@@ -23,14 +23,67 @@ En este ejercicio se va a construír un modelo de clases para la capa lógica de
* Agregar las dependencias de Spring.
* Agregar la configuración de Spring.
* Configurar la aplicación -mediante anotaciones- para que el esquema de persistencia sea inyectado al momento de ser creado el bean 'BlueprintServices'.
+Debemos revisar dependecias:
+
+
+
+
+Agregamos el @Service a la clase BlueprintsPersistence
+
+
+Creamos el archivo xml applicationContext.xml
+
+
+Añadimos la clase Main y lo conectamos con el archivo 'new ClassPathXmlApplicationContext("applicationContext.xml");'
+
2. Complete los operaciones getBluePrint() y getBlueprintsByAuthor(). Implemente todo lo requerido de las capas inferiores (por ahora, el esquema de persistencia disponible 'InMemoryBlueprintPersistence') agregando las pruebas correspondientes en 'InMemoryPersistenceTest'.
+El método getBluePrint() será @Override y actualizado con las condiciones necesarias
+
+
+El método addNewBlueprint(Blueprint bp), traera el dato dpp.saveBlueprint(bp);
+
+
+
+LLamaremos al método anterior desde la clase de BlueprintsPersistence
+
+
+Pruebas correspondientes a lo implementado anteriormente:
+
+
+
3. Haga un programa en el que cree (mediante Spring) una instancia de BlueprintServices, y rectifique la funcionalidad del mismo: registrar planos, consultar planos, registrar planos específicos, etc.
+Se deben realizar los siguientes cambios para las clases correspondientes para crear la instancia de BlueprintServices:
+a.
+
+b.
+
+c.
+
+d.
+
+
4. Se quiere que las operaciones de consulta de planos realicen un proceso de filtrado, antes de retornar los planos consultados. Dichos filtros lo que buscan es reducir el tamaño de los planos, removiendo datos redundantes o simplemente submuestrando, antes de retornarlos. Ajuste la aplicación (agregando las abstracciones e implementaciones que considere) para que a la clase BlueprintServices se le inyecte uno de dos posibles 'filtros' (o eventuales futuros filtros). No se contempla el uso de más de uno a la vez:
* (A) Filtrado de redundancias: suprime del plano los puntos consecutivos que sean repetidos.
* (B) Filtrado de submuestreo: suprime 1 de cada 2 puntos del plano, de manera intercalada.
+Se creara una carpeta de filters, con tres clases como se muestra a continuación:
+
+
+Clase BlueprintsFilter:
+
+
+Clase SubsamplingFilter:
+
+
+Clase RedundancyFilter:
+
+
+Y se realiza la inserción de dependencias por:
+
+
5. Agrege las pruebas correspondientes a cada uno de estos filtros, y pruebe su funcionamiento en el programa de prueba, comprobando que sólo cambiando la posición de las anotaciones -sin cambiar nada más-, el programa retorne los planos filtrados de la manera (A) o de la manera (B).
+
diff --git a/img/media/Image1.jpeg b/img/media/Image1.jpeg
new file mode 100644
index 0000000..19caa97
Binary files /dev/null and b/img/media/Image1.jpeg differ
diff --git a/img/media/Image10.jpeg b/img/media/Image10.jpeg
new file mode 100644
index 0000000..d73def3
Binary files /dev/null and b/img/media/Image10.jpeg differ
diff --git a/img/media/Image11.jpeg b/img/media/Image11.jpeg
new file mode 100644
index 0000000..69a9b1c
Binary files /dev/null and b/img/media/Image11.jpeg differ
diff --git a/img/media/Image12.jpeg b/img/media/Image12.jpeg
new file mode 100644
index 0000000..37a2351
Binary files /dev/null and b/img/media/Image12.jpeg differ
diff --git a/img/media/Image13.jpeg b/img/media/Image13.jpeg
new file mode 100644
index 0000000..0284206
Binary files /dev/null and b/img/media/Image13.jpeg differ
diff --git a/img/media/Image14.jpeg b/img/media/Image14.jpeg
new file mode 100644
index 0000000..0284206
Binary files /dev/null and b/img/media/Image14.jpeg differ
diff --git a/img/media/Image15.jpeg b/img/media/Image15.jpeg
new file mode 100644
index 0000000..b653723
Binary files /dev/null and b/img/media/Image15.jpeg differ
diff --git a/img/media/Image16.jpeg b/img/media/Image16.jpeg
new file mode 100644
index 0000000..a2cd891
Binary files /dev/null and b/img/media/Image16.jpeg differ
diff --git a/img/media/Image17.jpeg b/img/media/Image17.jpeg
new file mode 100644
index 0000000..9a5042a
Binary files /dev/null and b/img/media/Image17.jpeg differ
diff --git a/img/media/Image18.jpeg b/img/media/Image18.jpeg
new file mode 100644
index 0000000..24071d4
Binary files /dev/null and b/img/media/Image18.jpeg differ
diff --git a/img/media/Image19.jpeg b/img/media/Image19.jpeg
new file mode 100644
index 0000000..b6b7b9c
Binary files /dev/null and b/img/media/Image19.jpeg differ
diff --git a/img/media/Image2.jpeg b/img/media/Image2.jpeg
new file mode 100644
index 0000000..9126cfb
Binary files /dev/null and b/img/media/Image2.jpeg differ
diff --git a/img/media/Image20.jpeg b/img/media/Image20.jpeg
new file mode 100644
index 0000000..4db84a4
Binary files /dev/null and b/img/media/Image20.jpeg differ
diff --git a/img/media/Image3.jpeg b/img/media/Image3.jpeg
new file mode 100644
index 0000000..46e0348
Binary files /dev/null and b/img/media/Image3.jpeg differ
diff --git a/img/media/Image4.jpeg b/img/media/Image4.jpeg
new file mode 100644
index 0000000..e369479
Binary files /dev/null and b/img/media/Image4.jpeg differ
diff --git a/img/media/Image5.jpeg b/img/media/Image5.jpeg
new file mode 100644
index 0000000..e0ddc48
Binary files /dev/null and b/img/media/Image5.jpeg differ
diff --git a/img/media/Image6.jpeg b/img/media/Image6.jpeg
new file mode 100644
index 0000000..9884b6b
Binary files /dev/null and b/img/media/Image6.jpeg differ
diff --git a/img/media/Image7.jpeg b/img/media/Image7.jpeg
new file mode 100644
index 0000000..d138696
Binary files /dev/null and b/img/media/Image7.jpeg differ
diff --git a/img/media/Image8.jpeg b/img/media/Image8.jpeg
new file mode 100644
index 0000000..430e461
Binary files /dev/null and b/img/media/Image8.jpeg differ
diff --git a/img/media/Image9.jpeg b/img/media/Image9.jpeg
new file mode 100644
index 0000000..4ba6440
Binary files /dev/null and b/img/media/Image9.jpeg differ
diff --git a/pom.xml b/pom.xml
index 26a29df..54bed3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,6 @@
jar
Blueprints_Middleware
-
UTF-8
@@ -17,24 +16,53 @@
1.8
1.8
1.8
+ 3.2.10
+
- org.springframework
- spring-core
- 4.2.4.RELEASE
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+ ${spring-boot.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring-boot.version}
+
+
+
+
+ com.h2database
+ h2
+ runtime
+
+
+
- org.springframework
- spring-context
- 4.2.4.RELEASE
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.8.2
+ test
- junit
- junit
- 4.12
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.8.2
+ test
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
diff --git a/src/main/java/edu/eci/arsw/blueprints/filters/BlueprintsFilter.java b/src/main/java/edu/eci/arsw/blueprints/filters/BlueprintsFilter.java
new file mode 100644
index 0000000..457d322
--- /dev/null
+++ b/src/main/java/edu/eci/arsw/blueprints/filters/BlueprintsFilter.java
@@ -0,0 +1,6 @@
+package edu.eci.arsw.blueprints.filters;
+
+import edu.eci.arsw.blueprints.model.Blueprint;
+public interface BlueprintsFilter {
+ void filter(Blueprint bp);
+}
\ No newline at end of file
diff --git a/src/main/java/edu/eci/arsw/blueprints/filters/RedundancyFilter.java b/src/main/java/edu/eci/arsw/blueprints/filters/RedundancyFilter.java
new file mode 100644
index 0000000..4a483c4
--- /dev/null
+++ b/src/main/java/edu/eci/arsw/blueprints/filters/RedundancyFilter.java
@@ -0,0 +1,35 @@
+package edu.eci.arsw.blueprints.filters;
+
+import edu.eci.arsw.blueprints.model.Blueprint;
+import edu.eci.arsw.blueprints.model.Point;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+@Service
+public class RedundancyFilter implements BlueprintsFilter {
+
+ @Override
+ public void filter(Blueprint bp) {
+ List uniquePoints = new ArrayList<>();
+
+ for (Point i : bp.getPoints()) {
+ boolean found = false;
+ for (Point j : uniquePoints) {
+ if (i.equals(j)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ uniquePoints.add(i);
+ }
+ }
+
+ Point[] uniquePointsArray = uniquePoints.toArray(new Point[0]);
+
+ new Blueprint(bp.getAuthor(), bp.getName(), uniquePointsArray);
+ }
+}
diff --git a/src/main/java/edu/eci/arsw/blueprints/filters/SubsamplingFilter.java b/src/main/java/edu/eci/arsw/blueprints/filters/SubsamplingFilter.java
new file mode 100644
index 0000000..3004a89
--- /dev/null
+++ b/src/main/java/edu/eci/arsw/blueprints/filters/SubsamplingFilter.java
@@ -0,0 +1,27 @@
+package edu.eci.arsw.blueprints.filters;
+
+import edu.eci.arsw.blueprints.model.Blueprint;
+import edu.eci.arsw.blueprints.model.Point;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class SubsamplingFilter implements BlueprintsFilter {
+ @Override
+ public void filter(Blueprint bp) {
+ List oldPoints = bp.getPoints();
+ List sampledPoints = new ArrayList<>();
+
+ for (int i = 0; i < oldPoints.size(); i++) {
+ if (i % 2 == 0) {
+ sampledPoints.add(oldPoints.get(i));
+ }
+ }
+
+ // Convert ArrayList to Point array
+ Point[] sampledPointsArray = sampledPoints.toArray(new Point[0]);
+
+ new Blueprint(bp.getAuthor(), bp.getName(), sampledPointsArray);
+ }
+}
diff --git a/src/main/java/edu/eci/arsw/blueprints/model/Blueprint.java b/src/main/java/edu/eci/arsw/blueprints/model/Blueprint.java
index 9fd1cc6..d0fb636 100644
--- a/src/main/java/edu/eci/arsw/blueprints/model/Blueprint.java
+++ b/src/main/java/edu/eci/arsw/blueprints/model/Blueprint.java
@@ -1,4 +1,3 @@
-
package edu.eci.arsw.blueprints.model;
import java.util.ArrayList;
@@ -6,29 +5,32 @@
import java.util.List;
import java.util.Objects;
-
public class Blueprint {
- private String author=null;
-
- private List points=null;
-
- private String name=null;
-
- public Blueprint(String author,String name,Point[] pnts){
- this.author=author;
- this.name=name;
- points=Arrays.asList(pnts);
- }
-
- public Blueprint(String author, String name){
- this.name=name;
- points=new ArrayList<>();
+ private String author;
+ private List points;
+ private String name;
+
+ // Constructor que acepta un array de puntos
+ public Blueprint(String author, String name, Point[] pnts) {
+ this.author = author;
+ this.name = name;
+ this.points = new ArrayList<>(Arrays.asList(pnts)); // Convierte el array a una lista
}
+ // Constructor por defecto
public Blueprint() {
- }
-
+ this.points = new ArrayList<>();
+ }
+
+ // Constructor para inicializar con autor y nombre
+ public Blueprint(String author, String name) {
+ this.author = author;
+ this.name = name;
+ this.points = new ArrayList<>();
+ }
+
+ // Métodos getter
public String getName() {
return name;
}
@@ -36,56 +38,40 @@ public String getName() {
public String getAuthor() {
return author;
}
-
+
public List getPoints() {
return points;
}
-
- public void addPoint(Point p){
+
+ // Método para agregar un punto
+ public void addPoint(Point p) {
this.points.add(p);
}
+ // Método toString
@Override
public String toString() {
- return "Blueprint{" + "author=" + author + ", name=" + name + '}';
- }
-
- @Override
- public int hashCode() {
- int hash = 7;
- return hash;
+ return "Blueprint{" + "author=" + author + ", name=" + name + ", points=" + points + '}';
}
+ // Método equals
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
+ if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Blueprint other = (Blueprint) obj;
- if (!Objects.equals(this.author, other.author)) {
- return false;
- }
- if (!Objects.equals(this.name, other.name)) {
- return false;
- }
- if (this.points.size()!=other.points.size()){
- return false;
- }
- for (int i=0;i getAllBlueprints();
+
+ public List getAllKeys();
+
+ public Blueprint getBlueprintByAuthor(String author) throws BlueprintNotFoundException;
+
+ Set getBlueprintsByAuthor(String author) throws BlueprintNotFoundException;
}
diff --git a/src/main/java/edu/eci/arsw/blueprints/persistence/impl/InMemoryBlueprintPersistence.java b/src/main/java/edu/eci/arsw/blueprints/persistence/impl/InMemoryBlueprintPersistence.java
index 4506589..21694c0 100644
--- a/src/main/java/edu/eci/arsw/blueprints/persistence/impl/InMemoryBlueprintPersistence.java
+++ b/src/main/java/edu/eci/arsw/blueprints/persistence/impl/InMemoryBlueprintPersistence.java
@@ -1,8 +1,3 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
package edu.eci.arsw.blueprints.persistence.impl;
import edu.eci.arsw.blueprints.model.Blueprint;
@@ -10,40 +5,85 @@
import edu.eci.arsw.blueprints.persistence.BlueprintNotFoundException;
import edu.eci.arsw.blueprints.persistence.BlueprintPersistenceException;
import edu.eci.arsw.blueprints.persistence.BlueprintsPersistence;
-import java.util.HashMap;
-import java.util.Map;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
/**
- *
- * @author hcadavid
+ * In-memory implementation of BlueprintsPersistence.
+ * Stores blueprints in a HashMap.
*/
-public class InMemoryBlueprintPersistence implements BlueprintsPersistence{
+@Service
+public class InMemoryBlueprintPersistence implements BlueprintsPersistence {
- private final Map,Blueprint> blueprints=new HashMap<>();
+ private final Map, Blueprint> blueprints = new HashMap<>();
public InMemoryBlueprintPersistence() {
- //load stub data
- Point[] pts=new Point[]{new Point(140, 140),new Point(115, 115)};
- Blueprint bp=new Blueprint("_authorname_", "_bpname_ ",pts);
- blueprints.put(new Tuple<>(bp.getAuthor(),bp.getName()), bp);
-
- }
-
+ // Load stub data
+ Point[] pts = new Point[]{new Point(140, 140), new Point(115, 115)};
+ Blueprint bp = new Blueprint("_authorname_", "_bpname_", pts);
+ blueprints.put(new Tuple<>(bp.getAuthor(), bp.getName()), bp);
+ }
+
@Override
public void saveBlueprint(Blueprint bp) throws BlueprintPersistenceException {
- if (blueprints.containsKey(new Tuple<>(bp.getAuthor(),bp.getName()))){
- throw new BlueprintPersistenceException("The given blueprint already exists: "+bp);
+ if (blueprints.containsKey(new Tuple<>(bp.getAuthor(), bp.getName()))) {
+ throw new BlueprintPersistenceException("The given blueprint already exists: " + bp);
+ } else {
+ blueprints.put(new Tuple<>(bp.getAuthor(), bp.getName()), bp);
}
- else{
- blueprints.put(new Tuple<>(bp.getAuthor(),bp.getName()), bp);
- }
}
@Override
public Blueprint getBlueprint(String author, String bprintname) throws BlueprintNotFoundException {
- return blueprints.get(new Tuple<>(author, bprintname));
+ Blueprint blueprint = blueprints.get(new Tuple<>(author, bprintname));
+ if (blueprint == null) {
+ throw new BlueprintNotFoundException("Blueprint not found: " + author + ", " + bprintname);
+ }
+ return blueprint;
+ }
+
+ @Override
+ public Set getAllBlueprints() {
+ return new HashSet<>(blueprints.values());
+ }
+
+ @Override
+ public List getAllKeys() {
+ return new ArrayList<>(blueprints.keySet());
+ }
+
+ @Override
+ public Blueprint getBlueprintByAuthor(String author) throws BlueprintNotFoundException {
+ List authorBlueprints = new ArrayList<>();
+
+ for (Map.Entry, Blueprint> entry : blueprints.entrySet()) {
+ if (entry.getKey().getElem1().equals(author)) {
+ authorBlueprints.add(entry.getValue());
+ }
+ }
+
+ if (authorBlueprints.isEmpty()) {
+ throw new BlueprintNotFoundException("No blueprints found for author: " + author);
+ }
+
+ return authorBlueprints.get(0);
}
-
-
+ @Override
+ public Set getBlueprintsByAuthor(String author) throws BlueprintNotFoundException {
+ Set authorBlueprints = new HashSet<>();
+
+ for (Map.Entry, Blueprint> entry : blueprints.entrySet()) {
+ if (entry.getKey().getElem1().equals(author)) {
+ authorBlueprints.add(entry.getValue());
+ }
+ }
+
+ if (authorBlueprints.isEmpty()) {
+ throw new BlueprintNotFoundException("No blueprints found for author: " + author);
+ }
+
+ return authorBlueprints;
+ }
}
diff --git a/src/main/java/edu/eci/arsw/blueprints/persistence/impl/Tuple.java b/src/main/java/edu/eci/arsw/blueprints/persistence/impl/Tuple.java
index 64595bf..c24b0a7 100644
--- a/src/main/java/edu/eci/arsw/blueprints/persistence/impl/Tuple.java
+++ b/src/main/java/edu/eci/arsw/blueprints/persistence/impl/Tuple.java
@@ -3,7 +3,6 @@
import java.util.Objects;
public class Tuple {
-
T1 o1;
T2 o2;
@@ -34,21 +33,10 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
+ if (obj == null || getClass() != obj.getClass()) {
return false;
}
final Tuple, ?> other = (Tuple, ?>) obj;
- if (!Objects.equals(this.o1, other.o1)) {
- return false;
- }
- if (!Objects.equals(this.o2, other.o2)) {
- return false;
- }
- return true;
+ return Objects.equals(this.o1, other.o1) && Objects.equals(this.o2, other.o2);
}
-
-
}
diff --git a/src/main/java/edu/eci/arsw/blueprints/services/BlueprintsServices.java b/src/main/java/edu/eci/arsw/blueprints/services/BlueprintsServices.java
index cb99e66..bd9cd54 100644
--- a/src/main/java/edu/eci/arsw/blueprints/services/BlueprintsServices.java
+++ b/src/main/java/edu/eci/arsw/blueprints/services/BlueprintsServices.java
@@ -1,16 +1,12 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
package edu.eci.arsw.blueprints.services;
+import edu.eci.arsw.blueprints.filters.BlueprintsFilter;
import edu.eci.arsw.blueprints.model.Blueprint;
-import edu.eci.arsw.blueprints.model.Point;
import edu.eci.arsw.blueprints.persistence.BlueprintNotFoundException;
import edu.eci.arsw.blueprints.persistence.BlueprintsPersistence;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import edu.eci.arsw.blueprints.persistence.BlueprintPersistenceException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -21,37 +17,47 @@
*/
@Service
public class BlueprintsServices {
-
@Autowired
- BlueprintsPersistence bpp=null;
-
- public void addNewBlueprint(Blueprint bp){
-
+ private BlueprintsPersistence bpp;
+ @Autowired
+ private BlueprintsFilter filter;
+
+ public void addNewBlueprint(Blueprint bp) throws BlueprintPersistenceException {
+ bpp.saveBlueprint(bp);
}
-
- public Set getAllBlueprints(){
- return null;
+
+ public List getAllBlueprints() { // Cambia aquí el tipo de retorno
+ List val = new ArrayList<>(); // Cambia aquí el tipo de la variable
+ for (Blueprint b : bpp.getAllBlueprints()) {
+ val.add(b.toString());
+ }
+ return val;
}
-
+
/**
- *
+ *
* @param author blueprint's author
* @param name blueprint's name
* @return the blueprint of the given name created by the given author
* @throws BlueprintNotFoundException if there is no such blueprint
*/
- public Blueprint getBlueprint(String author,String name) throws BlueprintNotFoundException{
- throw new UnsupportedOperationException("Not supported yet.");
+ public Blueprint getBlueprint(String author, String name) throws BlueprintNotFoundException {
+ Blueprint blueprint = bpp.getBlueprint(author, name);
+ filter.filter(blueprint); // Aplicar filtro antes de retornar el plano
+ return blueprint;
}
-
+
/**
- *
+ *
* @param author blueprint's author
* @return all the blueprints of the given author
* @throws BlueprintNotFoundException if the given author doesn't exist
*/
- public Set getBlueprintsByAuthor(String author) throws BlueprintNotFoundException{
- throw new UnsupportedOperationException("Not supported yet.");
+ public Set getBlueprintsByAuthor(String author) throws BlueprintNotFoundException {
+ Set blueprints = bpp.getBlueprintsByAuthor(author);
+ for (Blueprint bp : blueprints) {
+ filter.filter(bp);
+ }
+ return blueprints;
}
-
}
diff --git a/src/main/java/edu/eci/arsw/blueprints/ui/Main.java b/src/main/java/edu/eci/arsw/blueprints/ui/Main.java
new file mode 100644
index 0000000..4b30f2c
--- /dev/null
+++ b/src/main/java/edu/eci/arsw/blueprints/ui/Main.java
@@ -0,0 +1,14 @@
+package edu.eci.arsw.blueprints.ui;
+
+import edu.eci.arsw.blueprints.persistence.BlueprintNotFoundException;
+import edu.eci.arsw.blueprints.services.BlueprintsServices;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class Main {
+ public static void main(String[] args) throws BlueprintNotFoundException { // Mover [] al tipo
+ ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
+ BlueprintsServices gc = ac.getBean(BlueprintsServices.class);
+ System.out.println(gc.getBlueprintsByAuthor("_authorname_"));
+ }
+}
diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml
new file mode 100644
index 0000000..0ea0c89
--- /dev/null
+++ b/src/main/resources/applicationContext.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
diff --git a/src/test/java/edu/eci/arsw/blueprints/persistence/impl/BlueprintFiltersTest.java b/src/test/java/edu/eci/arsw/blueprints/persistence/impl/BlueprintFiltersTest.java
new file mode 100644
index 0000000..3eba813
--- /dev/null
+++ b/src/test/java/edu/eci/arsw/blueprints/persistence/impl/BlueprintFiltersTest.java
@@ -0,0 +1,52 @@
+package edu.eci.arsw.blueprints.persistence.impl;
+
+import edu.eci.arsw.blueprints.filters.RedundancyFilter;
+import edu.eci.arsw.blueprints.filters.SubsamplingFilter;
+import edu.eci.arsw.blueprints.model.Blueprint;
+import edu.eci.arsw.blueprints.model.Point;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class BlueprintFiltersTest {
+
+ @Test
+ public void testRedundancyFilter() {
+ Point[] points = new Point[]{
+ new Point(0, 0), new Point(0, 0),
+ new Point(10, 10), new Point(10, 10)
+ };
+ Blueprint bp = new Blueprint("author1", "blueprint1", points);
+
+ RedundancyFilter filter = new RedundancyFilter();
+ filter.filter(bp);
+
+ Point[] expectedPoints = new Point[]{
+ new Point(0, 0), new Point(10, 10)
+ };
+ Blueprint expectedBp = new Blueprint("author1", "blueprint1", expectedPoints);
+
+ assertEquals(expectedBp.getPoints().size(), bp.getPoints().size());
+ assertEquals(expectedBp.getPoints(), bp.getPoints());
+ }
+
+ @Test
+ public void testSubsamplingFilter() {
+ Point[] points = new Point[]{
+ new Point(0, 0), new Point(1, 1),
+ new Point(2, 2), new Point(3, 3),
+ new Point(4, 4), new Point(5, 5)
+ };
+ Blueprint bp = new Blueprint("author2", "blueprint2", points);
+
+ SubsamplingFilter filter = new SubsamplingFilter();
+ filter.filter(bp);
+
+ Point[] expectedPoints = new Point[]{
+ new Point(0, 0), new Point(2, 2), new Point(4, 4)
+ };
+ Blueprint expectedBp = new Blueprint("author2", "blueprint2", expectedPoints);
+
+ assertEquals(expectedBp.getPoints().size(), bp.getPoints().size());
+ assertEquals(expectedBp.getPoints(), bp.getPoints());
+ }
+}
diff --git a/src/test/java/edu/eci/arsw/blueprints/test/persistence/impl/InMemoryPersistenceTest.java b/src/test/java/edu/eci/arsw/blueprints/test/persistence/impl/InMemoryPersistenceTest.java
index 844a6a3..54c4152 100644
--- a/src/test/java/edu/eci/arsw/blueprints/test/persistence/impl/InMemoryPersistenceTest.java
+++ b/src/test/java/edu/eci/arsw/blueprints/test/persistence/impl/InMemoryPersistenceTest.java
@@ -10,8 +10,7 @@
import edu.eci.arsw.blueprints.persistence.BlueprintNotFoundException;
import edu.eci.arsw.blueprints.persistence.BlueprintPersistenceException;
import edu.eci.arsw.blueprints.persistence.impl.InMemoryBlueprintPersistence;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import java.util.Set;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -20,55 +19,95 @@
* @author hcadavid
*/
public class InMemoryPersistenceTest {
-
+
@Test
- public void saveNewAndLoadTest() throws BlueprintPersistenceException, BlueprintNotFoundException{
- InMemoryBlueprintPersistence ibpp=new InMemoryBlueprintPersistence();
+ public void saveNewAndLoadTest() throws BlueprintPersistenceException, BlueprintNotFoundException {
+ InMemoryBlueprintPersistence ibpp = new InMemoryBlueprintPersistence();
+
+ Point[] pts0 = new Point[]{new Point(40, 40), new Point(15, 15)};
+ Blueprint bp0 = new Blueprint("mack", "mypaint", pts0);
- Point[] pts0=new Point[]{new Point(40, 40),new Point(15, 15)};
- Blueprint bp0=new Blueprint("mack", "mypaint",pts0);
-
ibpp.saveBlueprint(bp0);
-
- Point[] pts=new Point[]{new Point(0, 0),new Point(10, 10)};
- Blueprint bp=new Blueprint("john", "thepaint",pts);
-
+
+ Point[] pts = new Point[]{new Point(0, 0), new Point(10, 10)};
+ Blueprint bp = new Blueprint("john", "thepaint", pts);
+
ibpp.saveBlueprint(bp);
-
- assertNotNull("Loading a previously stored blueprint returned null.",ibpp.getBlueprint(bp.getAuthor(), bp.getName()));
-
- assertEquals("Loading a previously stored blueprint returned a different blueprint.",ibpp.getBlueprint(bp.getAuthor(), bp.getName()), bp);
-
- }
+ assertNotNull("Loading a previously stored blueprint returned null.", ibpp.getBlueprint(bp.getAuthor(), bp.getName()));
+
+ assertEquals("Loading a previously stored blueprint returned a different blueprint.", ibpp.getBlueprint(bp.getAuthor(), bp.getName()), bp);
+ }
@Test
public void saveExistingBpTest() {
- InMemoryBlueprintPersistence ibpp=new InMemoryBlueprintPersistence();
-
- Point[] pts=new Point[]{new Point(0, 0),new Point(10, 10)};
- Blueprint bp=new Blueprint("john", "thepaint",pts);
-
+ InMemoryBlueprintPersistence ibpp = new InMemoryBlueprintPersistence();
+
+ Point[] pts = new Point[]{new Point(0, 0), new Point(10, 10)};
+ Blueprint bp = new Blueprint("john", "thepaint", pts);
+
try {
ibpp.saveBlueprint(bp);
} catch (BlueprintPersistenceException ex) {
fail("Blueprint persistence failed inserting the first blueprint.");
}
-
- Point[] pts2=new Point[]{new Point(10, 10),new Point(20, 20)};
- Blueprint bp2=new Blueprint("john", "thepaint",pts2);
- try{
+ Point[] pts2 = new Point[]{new Point(10, 10), new Point(20, 20)};
+ Blueprint bp2 = new Blueprint("john", "thepaint", pts2);
+
+ try {
ibpp.saveBlueprint(bp2);
- fail("An exception was expected after saving a second blueprint with the same name and autor");
+ fail("An exception was expected after saving a second blueprint with the same name and author");
+ } catch (BlueprintPersistenceException ex) {
+ // Expected exception
}
- catch (BlueprintPersistenceException ex){
-
+ }
+
+ // New test for getAllBlueprints
+ @Test
+ public void getAllBlueprintsTest() {
+ InMemoryBlueprintPersistence ibpp = new InMemoryBlueprintPersistence();
+
+ Point[] pts1 = new Point[]{new Point(0, 0), new Point(10, 10)};
+ Blueprint bp1 = new Blueprint("john", "blueprint1", pts1);
+
+ Point[] pts2 = new Point[]{new Point(20, 20), new Point(30, 30)};
+ Blueprint bp2 = new Blueprint("paul", "blueprint2", pts2);
+
+ try {
+ ibpp.saveBlueprint(bp1);
+ ibpp.saveBlueprint(bp2);
+ } catch (BlueprintPersistenceException ex) {
+ fail("Blueprint persistence failed while saving blueprints.");
}
-
-
+
+ Set allBlueprints = ibpp.getAllBlueprints();
+ assertEquals("The number of blueprints retrieved does not match the expected size.", 3, allBlueprints.size());
}
+ // New test for getBlueprintsByAuthor
+ @Test
+ public void getBlueprintsByAuthorTest() {
+ InMemoryBlueprintPersistence ibpp = new InMemoryBlueprintPersistence();
+
+ Point[] pts1 = new Point[]{new Point(0, 0), new Point(10, 10)};
+ Blueprint bp1 = new Blueprint("john", "blueprint1", pts1);
+
+ Point[] pts2 = new Point[]{new Point(20, 20), new Point(30, 30)};
+ Blueprint bp2 = new Blueprint("john", "blueprint2", pts2);
-
-}
+ try {
+ ibpp.saveBlueprint(bp1);
+ ibpp.saveBlueprint(bp2);
+ } catch (BlueprintPersistenceException ex) {
+ fail("Blueprint persistence failed while saving blueprints.");
+ }
+
+ try {
+ Blueprint result = ibpp.getBlueprintByAuthor("john");
+ assertNotNull("No blueprints returned for the author 'john'.", result);
+ } catch (BlueprintNotFoundException ex) {
+ fail("BlueprintNotFoundException was thrown, but blueprints exist for the author.");
+ }
+ }
+}
\ No newline at end of file