From do-not-reply at jboss.org Tue Oct 5 09:29:50 2010
Content-Type: multipart/mixed; boundary="===============4354009352370440722=="
MIME-Version: 1.0
From: do-not-reply at jboss.org
To: gatein-commits at lists.jboss.org
Subject: [gatein-commits] gatein SVN: r4508 - in
components/common/trunk/common/src: test/java/org/gatein/common and 1 other
directory.
Date: Tue, 05 Oct 2010 09:29:49 -0400
Message-ID: <201010051329.o95DTnM1001264@svn01.web.mwc.hst.phx2.redhat.com>
--===============4354009352370440722==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: chris.laprun(a)jboss.com
Date: 2010-10-05 09:29:49 -0400 (Tue, 05 Oct 2010)
New Revision: 4508
Added:
components/common/trunk/common/src/main/java/org/gatein/common/RuntimeCo=
ntext.java
components/common/trunk/common/src/test/java/org/gatein/common/RuntimeCo=
ntextTestCase.java
Log:
- GTNCOMMON-12: Added RuntimContext to deal with gatein.runtime.context pro=
perty in an easier manner.
Added: components/common/trunk/common/src/main/java/org/gatein/common/Runti=
meContext.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/common/trunk/common/src/main/java/org/gatein/common/RuntimeC=
ontext.java (rev 0)
+++ components/common/trunk/common/src/main/java/org/gatein/common/RuntimeC=
ontext.java 2010-10-05 13:29:49 UTC (rev 4508)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.common;
+
+/**
+ * @author Chris Laprun
+ * @version $Revision$
+ */
+public class RuntimeContext
+{
+ public static final String GATEIN_RUNTIME_CONTEXT_PROP_NAME =3D "gatein=
.runtime.context";
+
+ private final RunningEnvironment ENV;
+
+ /**
+ * Only here for testing purposes... :(
+ *
+ * @param runtimeContextValue
+ */
+ RuntimeContext(String runtimeContextValue)
+ {
+ RunningEnvironment runningEnvironment =3D RunningEnvironment.UNKNOWN;
+ try
+ {
+ runningEnvironment =3D RunningEnvironment.valueOf(runtimeContextV=
alue);
+ }
+ catch (IllegalArgumentException e)
+ {
+ // nothing to do
+ }
+
+ ENV =3D runningEnvironment;
+ }
+
+ private RuntimeContext()
+ {
+ this(System.getProperty(GATEIN_RUNTIME_CONTEXT_PROP_NAME, RunningEnv=
ironment.gtn.getName()));
+ }
+
+ // On-demand class holder Singleton pattern (multi-thread safe)
+
+ private static final class InstanceHolder
+ {
+ public static final RuntimeContext instance =3D new RuntimeContext();
+ }
+
+ public static RuntimeContext getInstance()
+ {
+ return InstanceHolder.instance;
+ }
+
+ public enum RunningEnvironment
+ {
+ epp("epp"), gtn("gtn"), plf("plf"), UNKNOWN("__unknown__");
+
+ RunningEnvironment(String name)
+ {
+ this.name =3D name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ private final String name;
+ }
+
+ public boolean isRunningIn(RunningEnvironment env)
+ {
+ return ENV.equals(env);
+ }
+
+ public boolean isRunningInUnknownEnvironment()
+ {
+ return RunningEnvironment.UNKNOWN.equals(ENV);
+ }
+}
Added: components/common/trunk/common/src/test/java/org/gatein/common/Runti=
meContextTestCase.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/common/trunk/common/src/test/java/org/gatein/common/RuntimeC=
ontextTestCase.java (rev 0)
+++ components/common/trunk/common/src/test/java/org/gatein/common/RuntimeC=
ontextTestCase.java 2010-10-05 13:29:49 UTC (rev 4508)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.common;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Chris Laprun
+ * @version $Revision$
+ */
+public class RuntimeContextTestCase extends TestCase
+{
+ public void testDefaultShouldBeGateIn()
+ {
+ assertTrue(RuntimeContext.getInstance().isRunningIn(RuntimeContext.R=
unningEnvironment.gtn));
+ }
+
+ public void testIsUnknown()
+ {
+ System.setProperty(RuntimeContext.GATEIN_RUNTIME_CONTEXT_PROP_NAME, =
"foo");
+
+ assertTrue(RuntimeContext.getInstance().isRunningInUnknownEnvironmen=
t());
+ }
+
+ public void testKnownValues()
+ {
+ setAndAssert(RuntimeContext.RunningEnvironment.epp.getName());
+ setAndAssert(RuntimeContext.RunningEnvironment.gtn.getName());
+ setAndAssert(RuntimeContext.RunningEnvironment.plf.getName());
+ }
+
+ private void setAndAssert(final String value)
+ {
+ System.setProperty(RuntimeContext.GATEIN_RUNTIME_CONTEXT_PROP_NAME, =
value);
+
+ RuntimeContext instance =3D new RuntimeContext(value);
+ assertTrue(instance.isRunningIn(RuntimeContext.RunningEnvironment.va=
lueOf(value)));
+ }
+}
--===============4354009352370440722==--