1 23 24 package com.sun.enterprise.tools.verifier.tests.web.runtime; 25 26 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.tools.verifier.*; 29 import com.sun.enterprise.tools.verifier.tests.*; 30 import com.sun.enterprise.deployment.WebBundleDescriptor; 31 import com.sun.enterprise.tools.verifier.tests.web.*; 32 import com.sun.enterprise.deployment.runtime.common.*; 33 34 37 39 40 public class ASResourceRefName extends WebTest implements WebCheck { 41 42 public Result check(WebBundleDescriptor descriptor) { 43 String resrefName; 44 Result result = getInitializedResult(); 45 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 46 DefaultResourcePrincipal defPrincipal; 48 boolean oneFailed = false; 50 boolean notApp = false; 51 try{ 52 ResourceRef[] resRefs = (descriptor.getSunDescriptor()).getResourceRef(); 53 if (resRefs != null && resRefs.length > 0) { 54 for (int rep=0; rep<resRefs.length; rep++ ) { 55 resrefName = resRefs[rep].getResRefName(); 56 if (validResRefName(resrefName,descriptor)) { 57 addGoodDetails(result, compName); 58 result.passed(smh.getLocalString 59 (getClass().getName() + ".passed", 60 "PASSED [AS-WEB sun-web-app] resource-ref name [ {0} ] properly defined in the war file.", 61 new Object [] {resrefName})); 62 63 } 64 else { 65 oneFailed = true; 66 addErrorDetails(result, compName); 67 result.failed(smh.getLocalString 68 (getClass().getName() + ".failed", 69 "FAILED [AS-WEB sun-web-app] resource-ref name [ {0} ] is not valid, either empty or not defined in web.xml.", 70 new Object [] {resrefName})); 71 } 72 defPrincipal = resRefs[rep].getDefaultResourcePrincipal(); 74 if(defPrincipal != null){ 75 boolean defResourcePrincipalValid = true; 76 String defaultname = defPrincipal.getName(); 77 String defaultpassword = defPrincipal.getPassword(); 78 if((defaultname == null)||(defaultname.length() == 0)){ 79 oneFailed=true; 80 defResourcePrincipalValid = false; 81 addErrorDetails(result, compName); 82 result.failed(smh.getLocalString 83 (getClass().getName() + ".failed2", 84 "FAILED [AS-WEB resource-ref] name field in DefaultResourcePrincipal of ResourceRef [ {0} ] is not specified or is an empty string.", 85 new Object [] {resrefName})); 86 } 87 if((defaultpassword == null)||(defaultpassword.length() == 0)){ 88 oneFailed=true; 89 defResourcePrincipalValid = false; 90 addErrorDetails(result, compName); 91 result.failed(smh.getLocalString 92 (getClass().getName() + ".failed3", 93 "FAILED [AS-WEB resource-ref] password field in DefaultResourcePrincipal of ResourceRef [ {0} ] is not specified or is an empty string.", 94 new Object [] {resrefName})); 95 } 96 if(defResourcePrincipalValid){ 97 addGoodDetails(result, compName); 98 result.passed(smh.getLocalString 99 (getClass().getName() + ".passed3", 100 "PASSED [AS-WEB resource-ref] DefaultResourcePrincipal of ResourceRef [ {0} ] properly defined", 101 new Object [] {resrefName})); 102 } 103 } 104 } 106 } else { 107 notApp = true; 108 addNaDetails(result, compName); 109 result.notApplicable(smh.getLocalString 110 (getClass().getName() + ".notApplicable", 111 "NOT APPLICABLE [AS-WEB sun-web-app] resource-ref element not defined in the web archive [ {0} ].", 112 new Object [] {descriptor.getName()})); 113 } 114 if (oneFailed) { 115 result.setStatus(Result.FAILED); 116 } else if(notApp) { 117 result.setStatus(Result.NOT_APPLICABLE); 118 }else { 119 result.setStatus(Result.PASSED); 120 addGoodDetails(result, compName); 121 result.passed 122 (smh.getLocalString 123 (getClass().getName() + ".passed2", 124 "PASSED [AS-WEB sun-web-app] resource-ref element(s) are valid within the web archive [ {0} ] .", 125 new Object [] {descriptor.getName()} )); 126 } 127 }catch(Exception ex){ 128 oneFailed=true; 129 addErrorDetails(result, compName); 130 result.failed(smh.getLocalString 131 (getClass().getName() + ".failed4", "FAILED [AS-WEB resource-env-ref] Could not create the resource-ref")); 132 133 } 134 return result; 135 } 136 137 boolean validResRefName(String name,WebBundleDescriptor descriptor){ 138 boolean valid =true; 139 if(name !=null && name.length()!=0) { 140 try{ 141 descriptor.getResourceReferenceByName(name); 142 } 143 catch(IllegalArgumentException e){ 144 valid=false; 145 } 146 } else{ 147 valid=false; 148 149 } 150 151 return valid; 152 } 153 } 154 | Popular Tags |