View Javadoc
1   /*
2    * Copyright (c) 2002-2023, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.carto.business;
35  
36  import fr.paris.lutece.test.LuteceTestCase;
37  
38  import java.util.Optional;
39  
40  /**
41   * This is the business class test for the object Coordonnee
42   */
43  public class CoordonneeBusinessTest extends LuteceTestCase
44  {
45      private static final String ADRESSE1 = "Adresse1";
46      private static final String ADRESSE2 = "Adresse2";
47      private static final Double COORDONNEEX1 = 1.0;
48      private static final Double COORDONNEEX2 = 2.0;
49      private static final Double COORDONNEEY1 = 1.0;
50      private static final Double COORDONNEEY2 = 2.0;
51  
52      /**
53       * test Coordonnee
54       */
55      public void testBusiness( )
56      {
57          // Initialize an object
58      	DataLayer datalayer = new DataLayer( );
59      	datalayer.setId(1);
60          Coordonnee coordonnee = new Coordonnee( );
61          coordonnee.setAdresse( ADRESSE1 );
62          coordonnee.setCoordonneeX( COORDONNEEX1 );
63          coordonnee.setCoordonneeY( COORDONNEEY1 );
64          coordonnee.setGeoJson("geojson1");
65          coordonnee.setDataLayer(datalayer);
66  
67          // Create test
68          CoordonneeHome.create( coordonnee );
69          Optional<Coordonnee> optCoordonneeStored = CoordonneeHome.findByPrimaryKey( coordonnee.getId( ) );
70          Coordonnee coordonneeStored = optCoordonneeStored.orElse( new Coordonnee( ) );
71          assertEquals( coordonneeStored.getAdresse( ), coordonnee.getAdresse( ) );
72          assertEquals( coordonneeStored.getCoordonneeX( ), coordonnee.getCoordonneeX( ) );
73          assertEquals( coordonneeStored.getCoordonneeY( ), coordonnee.getCoordonneeY( ) );
74  
75          // Update test
76          coordonnee.setAdresse( ADRESSE2 );
77          coordonnee.setCoordonneeX( COORDONNEEX2 );
78          coordonnee.setCoordonneeY( COORDONNEEY2 );
79          coordonnee.setGeoJson("geojson2");
80          CoordonneeHome.update( coordonnee );
81          optCoordonneeStored = CoordonneeHome.findByPrimaryKey( coordonnee.getId( ) );
82          coordonneeStored = optCoordonneeStored.orElse( new Coordonnee( ) );
83  
84          assertEquals( coordonneeStored.getAdresse( ), coordonnee.getAdresse( ) );
85          assertEquals( coordonneeStored.getCoordonneeX( ), coordonnee.getCoordonneeX( ) );
86          assertEquals( coordonneeStored.getCoordonneeY( ), coordonnee.getCoordonneeY( ) );
87  
88          // List test
89          CoordonneeHome.getCoordonneesList( );
90  
91          // Delete test
92          CoordonneeHome.remove( coordonnee.getId( ) );
93          optCoordonneeStored = CoordonneeHome.findByPrimaryKey( coordonnee.getId( ) );
94          coordonneeStored = optCoordonneeStored.orElse( null );
95          assertNull( coordonneeStored );
96  
97      }
98  
99  }