Tools
Sign in
Login
Forum
Unit Tests for extensions
Forum
>
Extensions
>
Unit Tests for extensions
n/A
posted
on March 26, 2014
at 5:47 PM
n/A
posted
on March 26, 2014
at 5:47 PM
Is there examples/tutorials/cookbooks/recommendations for unit testing extensions ?
Thanks
n/A
replied
on March 27, 2014
at 9:47 AM
n/A
replied
on March 27, 2014
at 9:47 AM
Hi Nicolas,
the Developer forum covers topic related to Appway modeling. If you need some examples on unit testing for extensions we can discuss internally with R&D to provide you some. I will reach out to you via email.
n/A
replied
on March 27, 2014
at 1:53 PM
n/A
replied
on March 27, 2014
at 1:53 PM
I was struggling to get datasources working, as Appway will do a JNDI lookup which is usually provided by a container. As unit tests typically do not run in a container but in your IDE or CI server, there's no container managed persistency and therefor no JNDI context. I used
Simple JNDI
to stage the datasources and now my unit test which bootstraps Appway has a datasource in context. I used a bootstrap provided by Thomas, it works for 5.2 and requires little tweaking to work with 5.3. User will need to setup a data home on the FS.
1
2
3
package com.nm.test;
4
5
import com.nm.Nm;
6
import com.nm.sdk.data.User;
7
import com.nm.sdk.data.businessobjects.versioning.HeadFilter;
8
import com.nm.services.ApplicationServiceImpl;
9
import com.nm.utils.FileUtils;
10
import com.nm.utils.SystemServicesManager;
11
import com.nm.utils.SystemUtils;
12
import junit.framework.TestCase;
13
import org.apache.log4j.BasicConfigurator;
14
import org.apache.log4j.Level;
15
import org.apache.log4j.Logger;
16
17
import java.io.File;
18
import java.util.List;
19
20
/**
21
* Make sure the NM_DATA_HOME can be found via java vm parameter.
22
* For example: -Dnm.data.home=/Users/appway/my_data_home
23
*
24
* The data home should contain at least the conf folder /Users/appway/my_data_home/conf
25
*
26
* If you're using extensions they must be copied to /Users/appway/my_data_home/adapters
27
*
28
* start extension with AppwayTestCase.startExtension("MyExtension");
29
*
30
* stop extension with AppwayTestCase.stopExtension("MyExtension");
31
*/
32
public class AppwayTestCase extends TestCase {
33
34
private static SystemServicesManager systemServicesManager;
35
36
static {
37
// enable the correct parser
38
System.setProperty("org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser");
39
40
// configure loggers
41
BasicConfigurator.configure();
42
Logger.getRootLogger().setLevel(Level.WARN);
43
// Logger.getLogger("com.nm").setLevel(Level.DEBUG);
44
// Logger.getLogger("com.nm.sdk.utils.XMLUtils").setLevel(Level.ERROR);
45
// Logger.getLogger("com.nm.services.EventLogServiceImpl").setLevel(Level.WARN);
46
// Logger.getLogger("com.nm.sdk.data.expeval.NmConversionException").setLevel(Level.FATAL);
47
// Logger.getLogger("org.apache.commons").setLevel(Level.ERROR);
48
// Logger.getLogger(ReferenceCountManagerImpl.class.getPackage().getName()).setLevel(Level.DEBUG);
49
}
50
51
public AppwayTestCase() {
52
startupAppway();
53
}
54
55
/**
56
* prepare System Variables variables
57
*
58
* @throws Exception
59
*/
60
@Override
61
protected void setUp() throws Exception {
62
63
// init user
64
User user = new User("test");
65
user.setFirstName("Test");
66
user.setLastName("Testerson");
67
user.setPreference("email", "test.testerson@example.org");
68
user.setPreference("pid", "123456");
69
user.addToRole("User");
70
user.addToRole("Administrator");
71
72
// ensure test user exists and is used
73
if (Nm.getInstance().getUserService().getUser("test") == null) {
74
Nm.getInstance().getUserService().insertUser(user);
75
}
76
SystemUtils.setCurrentUser(user);
77
78
// ensure a proper version filter is set
79
SystemUtils.setCurrentVersionFilter(HeadFilter.WORKSPACE_INSTANCE);
80
}
81
82
/**
83
* Startup Appway
84
*/
85
private static void startupAppway() {
86
// start system services manager
87
if (systemServicesManager == null) {
88
systemServicesManager = new SystemServicesManager();
89
systemServicesManager.startupPhase1(null);
90
}
91
}
92
93
/**
94
* shutdown appway
95
*/
96
public static void shutdownAppway() {
97
// only shutdown if not already shutdown
98
if (systemServicesManager != null) {
99
100
// set shutdown mode
101
ApplicationServiceImpl.getInstance().setAppStateStopping();
102
103
// shutdown
104
systemServicesManager.shutdown(null);
105
106
// clean-up
107
systemServicesManager = null;
108
}
109
}
110
111
/**
112
* Clean the data home
113
*
114
* @return list of file that could not be deleted! this should be an empty list!
115
*/
116
public static synchronized List cleanDataHome() {
117
118
// vars
119
File dataHomeDirectory;
120
String dataHomePath;
121
122
// get data home path
123
dataHomePath = System.getProperty("nm.data.home");
124
if (dataHomePath == null) {
125
throw new RuntimeException("System parameter 'nm.data.home' not set.");
126
}
127
128
// drop existing data home and init new, empty one
129
dataHomeDirectory = new File(dataHomePath);
130
List filesUnableToDelete = FileUtils.delete(dataHomeDirectory);
131
File conf = new File(dataHomeDirectory, "conf");
132
conf.mkdirs();
133
134
return filesUnableToDelete;
135
}
136
137
/**
138
* start the adapter/extension with the given name
139
*
140
* @param name name of the adapter/extension to be started
141
*/
142
public void startExtension(String name) {
143
Nm.getInstance().getAdapterService().startAdapter(name);
144
}
145
146
/**
147
* stop the adapter/extension with the given name
148
*
149
* @param name name of the adapter/extension to be stopped
150
*/
151
public void stopExtension(String name) {
152
Nm.getInstance().getAdapterService().stopAdapter(name);
153
}
154
155
}
156
157
Please
sign in
to add a reply
About this site
|
Terms of use
|
Privacy statement
|
Contact us
© 2025 Appway AG. All Rights Reserved.
Thanks