View Javadoc
1   /*
2    * Copyright (c) 2002-2019, Mairie de 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  
35  package fr.paris.lutece.plugins.botpress.business;
36  
37  import fr.paris.lutece.test.LuteceTestCase;
38  
39  /**
40   * This is the business class test for the object BPBot
41   */
42  public class BPBotBusinessTest extends LuteceTestCase
43  {
44      private static final String BOTKEY1 = "BotKey1";
45      private static final String BOTKEY2 = "BotKey2";
46      private static final String NAME1 = "Name1";
47      private static final String NAME2 = "Name2";
48      private static final String DESCRIPTION1 = "Description1";
49      private static final String DESCRIPTION2 = "Description2";
50      private static final String AVATARURL1 = "AvatarUrl1";
51      private static final String AVATARURL2 = "AvatarUrl2";
52      private static final String LANGUAGE1 = "Language1";
53      private static final String LANGUAGE2 = "Language2";
54      private static final int BOTSTATUS1 = 1;
55      private static final int BOTSTATUS2 = 2;
56      private static final int ISSTANDALONE1 = 1;
57      private static final int ISSTANDALONE2 = 2;
58      private static final String WELCOMEMESSAGE1 = "WelcomeMessage1";
59      private static final String WELCOMEMESSAGE2 = "WelcomeMessage2";
60      private static final String SERVERURL1 = "ServerUrl1";
61      private static final String SERVERURL2 = "ServerUrl2";
62      private static final int APIVERSION1 = 1;
63      private static final int APIVERSION2 = 2;
64  
65      /**
66       * test BPBot
67       */
68      public void testBusiness( )
69      {
70          // Initialize an object
71          BPBot bPBot = new BPBot( );
72          bPBot.setBotKey( BOTKEY1 );
73          bPBot.setName( NAME1 );
74          bPBot.setDescription( DESCRIPTION1 );
75          bPBot.setAvatarUrl( AVATARURL1 );
76          bPBot.setLanguage( LANGUAGE1 );
77          bPBot.setBotStatus( BOTSTATUS1 );
78          bPBot.setIsStandalone( ISSTANDALONE1 );
79          bPBot.setWelcomeMessage( WELCOMEMESSAGE1 );
80          bPBot.setServerUrl( SERVERURL1 );
81          bPBot.setApiVersion( APIVERSION1 );
82  
83          // Create test
84          BPBotHome.create( bPBot );
85          BPBot bPBotStored = BPBotHome.findByPrimaryKey( bPBot.getId( ) );
86          assertEquals( bPBotStored.getBotKey( ), bPBot.getBotKey( ) );
87          assertEquals( bPBotStored.getName( ), bPBot.getName( ) );
88          assertEquals( bPBotStored.getDescription( ), bPBot.getDescription( ) );
89          assertEquals( bPBotStored.getAvatarUrl( ), bPBot.getAvatarUrl( ) );
90          assertEquals( bPBotStored.getLanguage( ), bPBot.getLanguage( ) );
91          assertEquals( bPBotStored.getBotStatus( ), bPBot.getBotStatus( ) );
92          assertEquals( bPBotStored.getIsStandalone( ), bPBot.getIsStandalone( ) );
93          assertEquals( bPBotStored.getWelcomeMessage( ), bPBot.getWelcomeMessage( ) );
94          assertEquals( bPBotStored.getServerUrl( ), bPBot.getServerUrl( ) );
95          assertEquals( bPBotStored.getApiVersion( ), bPBot.getApiVersion( ) );
96  
97          // Update test
98          bPBot.setBotKey( BOTKEY2 );
99          bPBot.setName( NAME2 );
100         bPBot.setDescription( DESCRIPTION2 );
101         bPBot.setAvatarUrl( AVATARURL2 );
102         bPBot.setLanguage( LANGUAGE2 );
103         bPBot.setBotStatus( BOTSTATUS2 );
104         bPBot.setIsStandalone( ISSTANDALONE2 );
105         bPBot.setWelcomeMessage( WELCOMEMESSAGE2 );
106         bPBot.setServerUrl( SERVERURL2 );
107         bPBot.setApiVersion( APIVERSION2 );
108         BPBotHome.update( bPBot );
109         bPBotStored = BPBotHome.findByPrimaryKey( bPBot.getId( ) );
110         assertEquals( bPBotStored.getBotKey( ), bPBot.getBotKey( ) );
111         assertEquals( bPBotStored.getName( ), bPBot.getName( ) );
112         assertEquals( bPBotStored.getDescription( ), bPBot.getDescription( ) );
113         assertEquals( bPBotStored.getAvatarUrl( ), bPBot.getAvatarUrl( ) );
114         assertEquals( bPBotStored.getLanguage( ), bPBot.getLanguage( ) );
115         assertEquals( bPBotStored.getBotStatus( ), bPBot.getBotStatus( ) );
116         assertEquals( bPBotStored.getIsStandalone( ), bPBot.getIsStandalone( ) );
117         assertEquals( bPBotStored.getWelcomeMessage( ), bPBot.getWelcomeMessage( ) );
118         assertEquals( bPBotStored.getServerUrl( ), bPBot.getServerUrl( ) );
119         assertEquals( bPBotStored.getApiVersion( ), bPBot.getApiVersion( ) );
120 
121         // List test
122         BPBotHome.getBPBotsList( );
123 
124         // Delete test
125         BPBotHome.remove( bPBot.getId( ) );
126         bPBotStored = BPBotHome.findByPrimaryKey( bPBot.getId( ) );
127         assertNull( bPBotStored );
128 
129     }
130 
131 }