incubator-lokahi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tob...@apache.org
Subject svn commit: r595389 - in /incubator/lokahi/lokahi/trunk/src/test: ./ org/ org/apache/ org/apache/lokahi/ org/apache/lokahi/core/ org/apache/lokahi/core/api/ org/apache/lokahi/core/api/environment/ org/apache/lokahi/core/api/instance/ org/apache/lokahi/...
Date Thu, 15 Nov 2007 18:39:02 GMT
Author: toback
Date: Thu Nov 15 10:39:01 2007
New Revision: 595389

URL: http://svn.apache.org/viewvc?rev=595389&view=rev
Log:
Added some junit tests for mysql.

Added:
    incubator/lokahi/lokahi/trunk/src/test/
    incubator/lokahi/lokahi/trunk/src/test/org/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/environment/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/environment/EnvironmentTest.java
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/instance/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/instance/InstanceTest.java
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/ipaddress/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/ipaddress/IpTest.java
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/DatabaseAuthenticationTest.java
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/NoAuthenticationTest.java
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/database/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/junit/
    incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/junit/MySqlSuite.java

Added: incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/environment/EnvironmentTest.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/environment/EnvironmentTest.java?rev=595389&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/environment/EnvironmentTest.java
(added)
+++ incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/environment/EnvironmentTest.java
Thu Nov 15 10:39:01 2007
@@ -0,0 +1,52 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+* 
+*   http://www.apache.org/licenses/LICENSE-2.0
+* 
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.core.api.environment;
+
+/**
+ * @author The Apache Incubated Lokahi project - http://incubator.apache.org/lokahi/
+ * @version $Id$
+ */
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+public class EnvironmentTest {
+    @Test
+    public void storeThenDelete() throws SQLException {
+        Environment e = new Environment("ToDelete", "Testing store than delete");
+        Environment e2 = new Environment("ToDelete", "Testing store than delete");
+        e = Environment.store(e);
+        int pk = e.getPk();
+        e2.setPk(pk);
+        Collection c = Environment.getEnviroments();
+        assertTrue(pk != 0);
+        assertTrue(e.equals(e2));
+        assertTrue(e.equals(e.get(pk)));
+        assertTrue(c.contains(e));
+        e.setName("ToDelete2");
+        Environment.update(e);
+        assertTrue(!e2.equals(e2.get(pk)));
+        assertTrue(e.equals(e.get(pk)));
+        assertTrue(Environment.delete(e));
+    }
+}

Added: incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/instance/InstanceTest.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/instance/InstanceTest.java?rev=595389&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/instance/InstanceTest.java
(added)
+++ incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/instance/InstanceTest.java
Thu Nov 15 10:39:01 2007
@@ -0,0 +1,52 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.core.api.instance;
+
+/**
+ * @author The Apache Incubated Lokahi project - http://incubator.apache.org/lokahi/
+ * @version $Id$
+ */
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+public class InstanceTest {
+    @Test
+    public void storeThenDelete() throws SQLException {
+        Instance e = new Instance("ToDelete", "Testing store than delete");
+        Instance e2 = new Instance("ToDelete", "Testing store than delete");
+        e = Instance.store(e);
+        int pk = e.getPk();
+        e2.setPk(pk);
+        Collection c = Instance.getInstances();
+        assertTrue(pk != 0);
+        assertTrue(e.equals(e2));
+        assertTrue(e.equals(e.get(pk)));
+        assertTrue(c.contains(e));
+        e.setName("ToDelete2");
+        Instance.update(e);
+        assertTrue(!e2.equals(e2.get(pk)));
+        assertTrue(e.equals(e.get(pk)));
+        assertTrue(Instance.delete(e));
+    }
+}

Added: incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/ipaddress/IpTest.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/ipaddress/IpTest.java?rev=595389&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/ipaddress/IpTest.java
(added)
+++ incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/api/ipaddress/IpTest.java
Thu Nov 15 10:39:01 2007
@@ -0,0 +1,52 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+* 
+*   http://www.apache.org/licenses/LICENSE-2.0
+* 
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.core.api.ipaddress;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author The Apache Incubated Lokahi project - http://incubator.apache.org/lokahi/
+ * @version $Id$
+ */
+public class IpTest {
+    @Test
+    public void storeThenDelete() throws SQLException {
+        Ip e = new Ip("172.16.12.12");
+        Ip e2 = new Ip("172.16.12.12");
+        e = Ip.store(e);
+        int pk = e.getPk();
+        e2.setPk(pk);
+        Collection c = Ip.getIps();
+        assertTrue(pk != 0);
+        assertTrue(e.equals(e2));
+        assertTrue(e.equals(e.get(pk)));
+        assertTrue(c.contains(e));
+        assertTrue(e.equals(Ip.getIp(e.getName(), false)));
+        e.setName("172.16.12.13");
+        Ip.update(e);
+        assertTrue(!e2.equals(e2.get(pk)));
+        assertTrue(e.equals(e.get(pk)));
+        assertTrue(Ip.delete(e));
+    }
+
+}

Added: incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/DatabaseAuthenticationTest.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/DatabaseAuthenticationTest.java?rev=595389&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/DatabaseAuthenticationTest.java
(added)
+++ incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/DatabaseAuthenticationTest.java
Thu Nov 15 10:39:01 2007
@@ -0,0 +1,47 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.core.common.authentication;
+/**
+* @author The Apache Incubated Lokahi project - http://incubator.apache.org/lokahi/
+* @version $Id$
+*/
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.apache.lokahi.core.common.exception.AuthenticationException;
+
+public class DatabaseAuthenticationTest {
+    Authentication auth;
+
+    @Before
+    public void loadAuth(){
+        auth = AuthenticationFactory.getAuthentication("org.apache.lokahi.core.common.authentication.DatabaseAuthentication");
+    }
+    @Ignore
+    @Test
+    public void goodAuthentication() throws AuthenticationException {
+    assertEquals(auth.authenticate("userA", "goodPass"), true);
+    }
+    
+    @Test
+    public void badAuthentication() throws AuthenticationException {
+    assertEquals(auth.authenticate("userA", "badPass"), false);
+    }
+}

Added: incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/NoAuthenticationTest.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/NoAuthenticationTest.java?rev=595389&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/NoAuthenticationTest.java
(added)
+++ incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/core/common/authentication/NoAuthenticationTest.java
Thu Nov 15 10:39:01 2007
@@ -0,0 +1,42 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+* 
+*   http://www.apache.org/licenses/LICENSE-2.0
+* 
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.core.common.authentication;
+/**
+* @author The Apache Incubated Lokahi project - http://incubator.apache.org/lokahi/
+* @version $Id$
+*/
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.apache.lokahi.core.common.exception.AuthenticationException;
+
+public class NoAuthenticationTest {
+    Authentication auth;
+
+    @Before
+    public void loadAuth(){
+        auth = AuthenticationFactory.getAuthentication("org.apache.lokahi.core.common.authentication.NoAuthentication");
+    }
+
+    @Test
+    public void noAuthentication() throws AuthenticationException {
+    assertEquals(auth.authenticate("userA", ""), true);
+    }
+}

Added: incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/junit/MySqlSuite.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/junit/MySqlSuite.java?rev=595389&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/junit/MySqlSuite.java (added)
+++ incubator/lokahi/lokahi/trunk/src/test/org/apache/lokahi/junit/MySqlSuite.java Thu Nov
15 10:39:01 2007
@@ -0,0 +1,86 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+* 
+*   http://www.apache.org/licenses/LICENSE-2.0
+* 
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.junit;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.BeforeClass;
+import org.apache.lokahi.core.common.authentication.NoAuthenticationTest;
+import org.apache.lokahi.core.common.authentication.DatabaseAuthenticationTest;
+import org.apache.lokahi.core.common.util.PropertiesFile;
+import org.apache.lokahi.core.common.database.CachingBroker;
+import org.apache.lokahi.core.common.database.ConnBean;
+import org.apache.lokahi.core.common.database.DerbyBroker;
+import org.apache.lokahi.core.api.environment.EnvironmentTest;
+import org.apache.lokahi.core.api.instance.InstanceTest;
+import org.apache.lokahi.core.api.ipaddress.IpTest;
+import org.apache.log4j.xml.DOMConfigurator;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ * @author The Apache Incubated Lokahi project - http://incubator.apache.org/lokahi/
+ * @version $Id$
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+        NoAuthenticationTest.class,
+        DatabaseAuthenticationTest.class,
+        EnvironmentTest.class,
+        InstanceTest.class,
+        IpTest.class
+        })
+public class MySqlSuite {
+
+    @BeforeClass
+    public static void startup() throws FileNotFoundException {
+
+        String prefix = "/Users/drtobes/lokahi/trunk/build/lokahi/gui/lokahi/WEB-INF/";
+        String file = "log4j.xml";
+        System.out.println("Configuring log4j with file " + prefix + file);
+        DOMConfigurator.configure(prefix + file);
+        String propsName = "lokahi.properties";
+        PropertiesFile.load(new FileInputStream(new File(prefix + "classes/" + propsName)));
+        PropertiesFile.load(new FileInputStream(new File(prefix + "classes/" + "db.properties")));
+
+        if (PropertiesFile.getConstantValue("lokahi.broker.implementation")!=null) {
+            CachingBroker.setMasterBrokerClassName(PropertiesFile.getConstantValue("lokahi.broker.implementation"));
+        }
+
+        // check for some specific init values that need non-standard action
+        System.out.println(PropertiesFile.getConstantValue("lokahi.broker.implementation"));
+        System.out.println(PropertiesFile.getConstantValue("tmc.database.uri"));
+        System.out.println(PropertiesFile.getConstantValue("tmc.database.user"));
+        System.out.println(PropertiesFile.getConstantValue("tmc.database.password"));
+        System.out.println(PropertiesFile.getConstantValue("tmc.database.driver"));
+        ConnBean.initializePool(PropertiesFile.getConstantValue("tmc.database.uri"),
+                                PropertiesFile.getConstantValue("tmc.database.user"),
+                                PropertiesFile.getConstantValue("tmc.database.password"),
+                                PropertiesFile.getConstantValue("tmc.database.driver")
+        );
+        DerbyBroker.initalize();
+        // If the Authenticate Module used is LDAPAuthenticate, initialize the variables
+        String auth_module = PropertiesFile.getConstantValue("AuthenticateModule");
+        System.out.println("auth_module = " + auth_module);
+    }
+}
+



Mime
View raw message