Browse files

Adding more tests and fixing issue for config caused by packaging

  • Loading branch information...
1 parent 8947154 commit a38170b85dd93bdd5837e147051be15417f753bb @pcon pcon committed Nov 30, 2012
Showing with 182 additions and 20 deletions.
  1. +90 −8 classes/Loggly_Configure_Controller.cls
  2. +75 −7 classes/Loggly_Test.cls
  3. +17 −5 pages/Loggly_Configure.page
View
98 classes/Loggly_Configure_Controller.cls
@@ -22,19 +22,101 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
public with sharing class Loggly_Configure_Controller {
- private final ApexPages.StandardController controller;
- private final LogglySettings__c record;
+ public static String MESSAGE_INCLUDE_HOSTNAME = 'Error: Hostname must be included if include hostname is checked';
+ private LogglySettings__c record;
+ public String recordName;
+ public String endpoint;
+ public String hostname;
+ public Boolean includeHostname;
- public Loggly_Configure_Controller(ApexPages.StandardController stdController) {
- this.controller = stdController;
- this.record = (LogglySettings__c) stdController.getRecord();
+ /** Gets the endpoint
+ *
+ * @return The endpoint
+ */
+ public String getEndpoint() {
+ return this.endpoint;
+ }
+
+ /** Sets the endpoint
+ *
+ * @param val The endpoint
+ */
+ public void setEndpoint(String val) {
+ this.endpoint = val;
+ }
+
+ /** Gets the hostname
+ *
+ * @return The hostname
+ */
+ public String getHostname() {
+ return this.hostname;
+ }
+
+ /** Sets the hostname
+ *
+ * @param val The hostname
+ */
+ public void setHostname(String val) {
+ this.hostname = val;
+ }
+
+ /** Gets the include hostname flag
+ *
+ * @return The include hostname flag
+ */
+ public Boolean getIncludeHostname() {
+ return (this.includeHostname == null) ? false : this.includeHostname;
+ }
- this.record.Name = Loggly.DEFAULT_SETTING_NAME;
+ /** Sets the include hostname flag
+ *
+ * @param val The include hostname flag
+ */
+ public void setIncludeHostname(Boolean val) {
+ this.includeHostname = val;
}
+ /** Gets the record name
+ * Defaults to the default name if not set
+ *
+ * @return The record name
+ */
+ public String getRecordName() {
+ if (recordName == null) {
+ recordName = Loggly.DEFAULT_SETTING_NAME;
+ }
+
+ return recordName;
+ }
+
+ /** The empty construtor */
+ public Loggly_Configure_Controller() {}
+
+ /** Creates a new loggly setting */
public PageReference create() {
- insert record;
- return new PageReference('/' + record.Id);
+ if (
+ this.includeHostname &&
+ (
+ this.hostname == null ||
+ this.hostname.trim() == ''
+ )
+ ) {
+ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, MESSAGE_INCLUDE_HOSTNAME);
+ ApexPages.addMessage(myMsg);
+ return null;
+ }
+
+
+ this.record = new LogglySettings__c();
+ this.record.Name = getRecordName();
+ this.record.Endpoint__c = getEndpoint();
+ this.record.Hostname__c = getHostname();
+ this.record.Include_Hostname__c = getIncludeHostname();
+
+ insert this.record;
+
+ return new PageReference('/' + this.record.Id);
}
}
View
82 classes/Loggly_Test.cls
@@ -1065,6 +1065,31 @@ public class Loggly_Test {
System.assertEquals(null, Loggly.cache, 'Cache should still be empty since we are not batching');
}
+ static testMethod void controller_setters_test() {
+ String newDefault = '_default_loggly_';
+ String endpoint = 'test://myurl';
+ String hostname_val = '_unitest_hostname_';
+
+ Test.startTest();
+
+ Loggly.DEFAULT_SETTING_NAME = newDefault;
+
+ PageReference p = Page.Loggly_Configure;
+ Test.setCurrentPage(p);
+ Loggly_Configure_Controller controller = new Loggly_Configure_Controller();
+
+ controller.setEndpoint(endpoint);
+ controller.setHostname(hostname_val);
+ controller.setIncludeHostname(true);
+
+ System.assertEquals(newDefault, controller.getRecordName(), 'Did not get the right name back');
+ System.assertEquals(endpoint, controller.getEndpoint(), 'Did not get the same endpoint back');
+ System.assertEquals(hostname_val, controller.getHostname(), 'Did not get the same hostname back');
+ System.assert(controller.getIncludeHostname(), 'Did not get the same include hostname back');
+
+ Test.stopTest();
+ }
+
static testMethod void controller_test() {
String newDefault = '_default_loggly_';
String endpoint = 'test://myurl';
@@ -1074,17 +1099,16 @@ public class Loggly_Test {
// does not fail because the default has already been created
Loggly.DEFAULT_SETTING_NAME = newDefault;
- LogglySettings__c testSettings = new LogglySettings__c();
- testSettings.Endpoint__c = endpoint;
- testSettings.Hostname__c = hostname_val;
- testSettings.Include_Hostname__c = true;
-
Test.startTest();
PageReference p = Page.Loggly_Configure;
Test.setCurrentPage(p);
- ApexPages.StandardController sc = new ApexPages.StandardController(testSettings);
- Loggly_Configure_Controller controller = new Loggly_Configure_Controller(sc);
+ Loggly_Configure_Controller controller = new Loggly_Configure_Controller();
+
+ controller.setEndpoint(endpoint);
+ controller.setHostname(hostname_val);
+ controller.setIncludeHostname(true);
+
controller.create();
Test.stopTest();
@@ -1103,4 +1127,48 @@ public class Loggly_Test {
System.assertEquals(hostname_val, result.Hostname__c, 'Did not get the right hostname');
System.assert(result.Include_Hostname__c, 'Did not get the right include hostname');
}
+
+ static testMethod void controller_nohostname_test() {
+ String newDefault = '_default_loggly_';
+ String endpoint = 'test://myurl';
+ String hostname_val = '_unitest_hostname_';
+
+ //This is kind of lame, but we have to do this to make sure that it
+ // does not fail because the default has already been created
+ Loggly.DEFAULT_SETTING_NAME = newDefault;
+
+ Test.startTest();
+
+ PageReference p = Page.Loggly_Configure;
+ Test.setCurrentPage(p);
+ Loggly_Configure_Controller controller = new Loggly_Configure_Controller();
+
+ controller.setEndpoint(endpoint);
+ controller.setIncludeHostname(true);
+
+ controller.create();
+
+ Test.stopTest();
+
+ List<ApexPages.Message> messages = ApexPages.getMessages();
+
+ System.assertEquals(1, messages.size(), 'Did not get the right number of messages');
+ System.assertEquals(Loggly_Configure_Controller.MESSAGE_INCLUDE_HOSTNAME, messages.get(0).getSummary(), 'Did not get the right summary');
+
+ try {
+ LogglySettings__c result = [
+ select Endpoint__c,
+ Hostname__c,
+ Include_Hostname__c,
+ Name
+ from LogglySettings__c
+ where Name = :newDefault
+ ];
+ System.assert(false, 'We should not have gotten this far.');
+ } catch (System.QueryException e) {
+ System.assert(true, 'Got the exception we expected');
+ } catch (Exception e) {
+ System.assert(false, 'Got an exception we did not expect [' + e.getTypeName() + ': ' + e.getMessage() + ']');
+ }
+ }
}
View
22 pages/Loggly_Configure.page
@@ -1,4 +1,4 @@
-<apex:page showHeader="true" title="Loggly Configuration" standardController="LogglySettings__c" extensions="Loggly_Configure_Controller">
+<apex:page showHeader="true" title="Loggly Configuration" controller="Loggly_Configure_Controller">
<apex:form id="form">
<apex:pageMessages />
<apex:pageBlock title="Create Loggly settings">
@@ -9,10 +9,22 @@
For more information about configuring Loggly prior to use, read the documentation at <a href="http://solenopsis.org/sloggly/">http://solenopsis.org/sloggly/</a>
</apex:pageBlockSection>
<apex:pageBlockSection title="" columns="2" collapsible="false" showHeader="false">
- <apex:outputField value="{!LogglySettings__c.Name}" />
- <apex:inputField value="{!LogglySettings__c.Endpoint__c}" required="true" />
- <apex:inputField value="{!LogglySettings__c.Hostname__c}" required="false" />
- <apex:inputField value="{!LogglySettings__c.Include_Hostname__c}" required="false" />
+ <apex:pageBlockSectionItem >
+ <apex:outputLabel for="name" value="{!$ObjectType.LogglySettings__c.fields.Name.label}" />
+ <apex:outputText value="{!recordName}" id="name" />
+ </apex:pageBlockSectionItem>
+ <apex:pageBlockSectionItem >
+ <apex:outputLabel for="endpoint" value="{!$ObjectType.LogglySettings__c.fields.Endpoint__c.label}" />
+ <apex:inputText value="{!endpoint}" id="endpoint" required="true" />
+ </apex:pageBlockSectionItem>
+ <apex:pageBlockSectionItem >
+ <apex:outputLabel for="hostname" value="{!$ObjectType.LogglySettings__c.fields.Hostname__c.label}" />
+ <apex:inputText value="{!hostname}" id="hostname" />
+ </apex:pageBlockSectionItem>
+ <apex:pageBlockSectionItem >
+ <apex:outputLabel for="includeHostname" value="{!$ObjectType.LogglySettings__c.fields.Include_Hostname__c.label}" />
+ <apex:inputCheckbox value="{!includeHostname}" id="includeHostname" />
+ </apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

0 comments on commit a38170b

Please sign in to comment.